- Home /
Question by
JackMini36 · May 14, 2016 at 07:02 PM ·
c#rotationsteering
Smooth rotation for seek steering behavior
Hello,
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
Comment
How about looking at the current moveVector right before moving?
Your answer

Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
LookAt + Raycasting makes weapon rotate in a weird way 0 Answers