I have set the collider’s rotation along all axes to zero. I have constrained the collider’s position and rotation along its XYZ axes. I have added mass to its rigidbody. I have checked the the rotation of the game object during animation in Blender (it was upright).
Yet, whenever I hit play, the collider rotates back along the X axis, making the AI appear to be leaning back about 10 degrees. Regardless of the direction he is moving, he looks like he is going to fall backwards.
Any suggestions?
Update: I tried adding this to the Update function.
I had set the enemy AI’s target position along the Z, X and Y axes. This caused the enemy AI to “tilt” up or down along its own Y axis in order to reach the target.
To fix the tilting, I just zeroed out the Y axis value of the target position. I found the following code on the answer to another question, elsewhere on the forum.
Hat tip, and many, many thanks, to Aldo Netto.
function Update () {
var lookDir = target.position - myTransform.position;
lookDir.y = 0; // zero the height difference
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}