Keep agent object upright via AI Lerp or other script?

This is kind of the place, because I want performant, and I already have the agent being turned to face its destination. SO I was wondering if there is a way to include a restraint on the X and Z at the same time so the AILerp agent stays upright, better than looking real funny on hillsides or if on top of a sharpers peak, sometimes they twist 90 degrees and are almost laying down on their faces or backs.


Do you think you could show a screenshot or video of this?

I am not sure why they would do this, as their turn towards commands are only given during AStar, and I am using kinematic rigidbodies, because I dont want physics interfering, so I dont think it is Unity just making them follow the normals of the map, because AFAIK that is not standard unity behavior when moving objects. Root motion is off.

This map is a mesh, not a terrain.


The AILerp script always aligns itself with the path. It doesn’t really care about the ground at all.

If you want a movement script that moves more horizontally I would recommend the AIPath script.


In the meantime, I had the same problem with my airships, as they were facing funny directions, and ended up coding a fast solution for this problem.

I am needing really lightweight pathing, I am thinking, for the overland map, coudl be a TON going on in late game.

So I went to line 590 of AILerp and added a line 591: direction.y = 0;

Seems to have done the trick with my initial tests.

1 Like

Because of the update, Add “direction.y = 0;” after line 627 in AILerp to keep your units/characters upright.

This is in the MovementUpdate() method, right after the line

nextPosition = CalculateNextPosition(out direction, isStopped ? 0f : deltaTime);