When an Enemy in my game (RPGish) becomes aware of the player and gives chase, it falls through the terrain if there's a height difference (uneven/hilly terrain); Enemy has Character Controller/Motor but no Rigidbody. I was using this:
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
I have read that manipulation of the transform.position is common with object fall throughs. After many attempts, I ended up with this:
CharacterController cc = GetComponent();
Vector3 forward = transform.TransformDirection(Vector3.forward);
cc.SimpleMove(forward * moveSpeed * Time.deltaTime);
and my Enemy has stopped falling through the ground. I changed moveSpeed from 4 (with failed/fall through code) to 299 to make it approx. the same speed and, to be honest, I have no idea why. Have I done something unexpected that will cause me headaches later with this movement code? Is there a standard practice for moving an AI unit around on uneven terrain?
↧