First post, and I have been teaching myself over the last month, so bear with me.
----------
I have a great enemy patrol script made up, and constructed a low poly terrain to test it on angled and sloped terrains. Everything is working perfectly, however, I cannot figure out for the life of me how to get the rotation the enemy makes when switching angles along the terrain to be smooth.
----------
This is currently what I am trying with no luck.
I have used Slerp before with success, but no dice here. The enemy acts as if the script is doing nothing, ie, stays upright when going down a slope.
----------
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.down, out hit, whatIsGround)){
Quaternion terrainAngle = Quaternion.LookRotation(Vector3.Cross(transform.right, hit.normal));
transform.rotation = Quaternion.Slerp(transform.rotation, terrainAngle, Time.deltaTime * 2f);
}
----------
If I simply make the transform.rotation = terrainAngle, the enemy angles properly along the terrain, but its transistions are abrupt and not smooth.
What am I missing here?
↧