How to make sure that the Agent is always Perpendicular to the walkable surface?

Hey!

Usually you want to have a trigger collider or a raycast that shoots from the Agents downwards. This helps you to check if the Agent is grounded but in terms of a Raycast you will get back RaycastHit struct with all the info about the object that you have detected - in this case it would be the surface.

If you take a look at the RaycastHit documentation Unity - Scripting API: RaycastHit you will find that it have a Vector3 normal which is just a vector coming out of the surface mesh upwards and generally gives you the perpendicular direction “up” (I am fairly sure that you can get similar info rom a trigger collider).

You can rotate / align your Agents transform to have its transform.up match the normal of the surface which should make your Agent always perpendicular to the surface.

I think that you can use Quaternion.FromToRotation to find the correct rotation.

You can check out this thread to learn more Character align to surface normal ???

I hope it helps!