# Problems with transform.forward and Vector3.Slerp

Basically I have a ship that I want to move through waypoints drawn. The problem i’m having is with the turning of the ship. It has worked for me in the past and it originally came from the forums.

The ship just goes off on another direction and not towards the waypoint.

``````speed += myAcceleration * acceleration * Time.deltaTime;

if( speed > maxspeed )

speed = maxspeed;

else if ( speed < minspeed )

speed = minspeed;

transform.Translate(0, 0, speed * Time.deltaTime);
transform.forward = Vector3.Slerp(transform.forward, drawPath.pathPoints[currentWaypoint], Time.deltaTime * steerSpeed);
``````

I have never seen it done like that, and not sure how changing transform.forward is supposed to work.
Here is how I do it, based on examples from Unity docs and elsewhere I have seen:

``````// calculate the angle to turn to point at the target
startAngle  = transform.rotation;
destAngle  = Quaternion.LookRotation( target.position  - transform.position);
newAngle = Quaternion.Lerp( startAngle, destAngle, Time.deltaTime * turnSpeed);
transform.rotation = newAngle;

transform.Translate(0, 0, speed * Time.deltaTime);
``````

thanks it works as in it now follows the path, but it rotates around more than just the Y axis. If I make destAngle.eulerAngles.x = 0; destAngle.eulerAngles.z = 0;after LookRotation they still change slightly but for now it will do. Thanks again.

Maybe if you make newAngle.x = newAngle.z = 0 there will be no rotation other than on Y, rather than on destAngle.

Another option would be to match the y of the target to the ship by making the target = Vector3( target.position.x, transform.position.y, target.position.z)

Both of those would be for a ship that is on the flat surface of water, whereas the first example could work for a space ship.