When rotating an object the resulting angle is dfferent from what I set.

Hello all,

I’m coming across this issue and hope that someone can shed some light on the problem.

I’m rotating an object, which at the moment is a cube towards a given point in world space.

I’m calculating the point to look towards from a touch event, which I convert from screen coords to world coords.

I’m then doing the following…

void Update(){
   var direction = (newVector - transform.position).normalized
   var lookRotation = Quaternion.LookRotation(direction);

   this.transform.rotation = Quaternion.Slerp(this.transform.rotation, lookRotation, time.deltaTeim * RotationSpeed);
}

The rotation is to be on the z-axis. Now, from that it does rotate the object no the zaxis, but the resulting angle of rotation is a small fraction of what is should be. For example :

The angle, which should be 1.104 in radians, is being set on the object as 0.37.

Does anyone have any ideas as to what I’m missing here.

Thanks for your time.

I assume this is example code since you misspelled ‘deltaTime’? As for the angle, I’m not sure where you are reading them. If you are getting the angle from Transform.rotation, then be aware that a rotation is a Quaternion, a 4D, non-intuitive construct. The x,y,z,w values for a Quaternion are in the range of 0.0 to 1.0 and are not radians.

Also on line 2, you don’t have to normalize the vector. As for getting the code to rotate on the ‘z’ axis, there is an optional parameter to LookRotation() that specifies the up vector. Try this:

var lookRotation = Quaternion.LookRotation(direction, Vector3.forward);