I am moving the character by force using this:
var vertical = Input.GetAxisRaw ("Vertical");
var forwardMoveAmount = vertical * moveSpeed * 100;
if (vertical > 0.0f) {
rigidbody.AddRelativeForce (0, 0, forwardMoveAmount);
} else if (vertical < 0.0f) {
rigidbody.AddRelativeForce (0, 0, forwardMoveAmount);
} else {
if (rigidbody.velocity.z != 0) {
rigidbody.AddRelativeForce (0, 0, -forwardMoveAmount * moveSpeed * Time.deltaTime * 2);
}
}
And turning the character like this:
float h = Input.GetAxisRaw ("Horizontal");
Vector3 a = transform.localEulerAngles;
// Turns the character to the forward direction
if (h > 0.1)
transform.localEulerAngles = new Vector3 (a.x, a.y + (turnSpeed * Time.deltaTime * 20), a.z);
else if (h < 0)
transform.localEulerAngles = new Vector3 (a.x, a.y - (turnSpeed * Time.deltaTime * 20), a.z);
This works fine to player, but I’m trying to develop an AI and I can’t figure out how to smoothly change the direction of the AI to the new point in path. For now I am setting the new waypoint and just pointing the AI to there using LookAt. How can I “smooth” or damp the curve to a more natural behaviour?