I am trying to implement Reynolds' seek steering behaviour, but I am having problems on the rotation part. This is what I have:
void FixedUpdate()
{
// get position of current waypoint
Vector3 targetPos = new Vector3(path[currentWaypoint].x, transform.position.y, path[currentWaypoint].z);
// velocity vector towards target
Vector3 desiredVelocity = targetPos - transform.position;
// calculate the steerforce required for the desired velocity based on current velocity
Vector3 steerForce = desiredVelocity - currentVelocity;
steerForce = new Vector3(steerForce.x, 0, steerForce.z);
steerForce = Vector3.ClampMagnitude(steerForce, maxSteer);
// create a move vector to be added to agent's current position
// Then normalize it so it can be scaled according to the agent's max speed
Vector3 moveVector = steerForce.normalized * moveSpeed * Time.fixedDeltaTime;
transform.Translate(moveVector);
}
How would I do it so my agent will be rotated smoothly based only on the code above? I tried rotating based on the current velocity, but the agents is rapidly rotated in one frame towards the target waypoint. I am not working with rigidbodies.
Am I doing something wrong? What am I missing?
Thanks, Jack