Support Forum

Rotating agent to terrain normal

Hi Guys,

We are building an RTS game and need to have our units to rotate to the surface of the terrain.

I have tried rigging the unit with a raycast group positioned at the 4 corners of the unit, this doesn’t work yet but my concern is performance when dealing with 100’s possibly 1000’s of units.

I have an option to use the terrain normals but this also doesn’t appear to work, I was then thinking if it’s possible to handle this by using either the units path or the generated recast graph?

Any advice or pointers would be awesome, thank you for your time.

All the best

Hi

I’d not recommend using the path or navmesh normal. They will be too visually inaccurate.
However I can recommend caching the raycast results. One thing I did for another game was to store the hit point + the hit normal as a plane every time I did a raycast. Then for the next few frames (maybe 5 or so) I would not do a raycast, but instead check the intersection of the ray with the previously cached plane. That is much faster than a raycast, and since the terrain is locally well approximated by a plane it can significantly cut down on the number of raycasts you need to do per frame.

Hi, Just an update we have successfully got unit orientation to terrain now by using the LateUpdate method :smiley:

1 Like