# Rotate transform to point at vector location

Hello,

I’m trying to rotate a model (over time) to point at a vector location. I am running into some problems with quaternions, floats and vectors.

I want to:

Figure out the angle between the current model’s direction and then rotate it over time until it points to the vector location.

I have tried:

``````var target = Vector3(random_x, 0.0, random_z);
var targetDir = target - transform.position;
var forward = transform.forward;
rotation_diff = Vector3.Angle(targetDir, forward);

While (rotation_diff>1.0){

transform.Rotate(0, Time.deltaTime, 0);
targetDir = target - transform.position;
forward = transform.forward;
rotation_diff = Vector3.Angle(targetDir, forward);
yield;

}
``````

I’m getting an error 'cannot convert float to UnityEngine.Vector3 from this line “rotation_diff=Vector3.Angle(targetDir,forward);”

transform.LookAt works, but it does it instantly so the model just points in the new direction and doesn’t turn to it.

This must be a really simple thing to do, but I seem to be banging my head against the wall.Thank you for any help!

Jason

I might use LookAt + Quaternion.Slerp, using a technique like this.

–Eric

Thank you Eric! This works perfectly:

``````			var oldRotation = transform.rotation;
var target = Vector3(random_x, 0.0, random_z);
transform.LookAt(target);
var newRotation = transform.rotation;

for (t=0.0; t<=1.0; t+=Time.deltaTime)
{
transform.rotation = Quaternion.Slerp(oldRotation,newRotation, t);
yield;
}

transform.rotation = newRotation; //to make it come out exactly right
``````

Jason