- Home /
Character height issue
Hello:
I'm creating a game that deforms terrain on the fly, and the character should always be over the terrain. Now, there are moments when I raise the terrain too high and I don't want the character to move through the terrain, so I change the position constantly, but that creates motion sickness. Is there a way I can fix this? Here's my code:
transform.Translate(Vector3.forward * (movementSpeed / 2) * Time.deltaTime);
float height = 0;
Vector3 terrainPos = Vector3.zero;
terrainPos = transform.GetComponent<ViewHelper>().underHit.collider.gameObject.GetComponent<Terrain>().transform.position;
height = transform.GetComponent<ViewHelper>().underHit.collider.gameObject.GetComponent<Terrain>().SampleHeight(transform.position);
transform.position = new Vector3(transform.position.x, terrainPos.y + extraHeight + height, transform.position.z);
I need to create the most smooth motion possible. Any help is appreciated.
Comment
Your answer
Follow this Question
Related Questions
Incorrect height with sampleHeight 1 Answer
Editing Terrain Topology at Runtime 0 Answers
Terrain height raycasting? 1 Answer
Unity 5 Terrain glitch 0 Answers
Get Height of Terrain in Script 1 Answer