I’m trying to make a character rotate and move towards a target object. I can get him to rotate and move straight towards the object, but his movement is very jittery - mainly the vertical axis. He seems to constantly bob up and down in place. How can I make this movement nice and clear?
Here is what my code looks like: (it works by checking if myCharacter is close to targetObject - if myCharacter has a dist of greater than 4, then myCharacter moves towards targetObject until dist is less than 4 - in which myCharacter will stand still).
myCharacter.transform.LookAt(targetObject.transform);
dist = Vector3.Distance(myCharacter.transform.position, targetObject.transform.position);
if(dist < 4){
transform.eulerAngles.x = 0;
transform.eulerAngles.z = 0;
}
else{
transform.position += transform.forward * 0.1;//Time.deltaTime;
}