Add 90 Degrees to Transform.Rotation

Hello,

Haven’t been using Unity for a while and I’ve kind’a forgotten a few simple things, basically I’m using a ‘LookAt’ technique by using a transform.rotation = Quaternion.Slerp.

    var lookPos = target.position - transform.position;
	lookPos.y = 0;
	
	var rotation = Quaternion.LookRotation(lookPos);
	var adjustRotation = transform.rotation.y + rotationAdjust;
	
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

The only thing I want to do I to add an extra 90 degrees to the transform rotation because the transform doesn’t actually look at ‘rotation’, its 90 degrees off.

Cheers

You can’t modify the components of transform.rotation directly: this property is a quaternion, and its components have nothing to do with the familiar x, y, z angles that appear in the Inspector/Transform/Rotation (these are actually the eulerAngles).

In this case, you should multiply the lookAt quaternion by a 90 degrees rotation - in the quaternion world, multiply actually means combine. Supposing you need this extra rotation around the Y axis, you could do the following:

var lookPos = target.position - transform.position;
lookPos.y = 0;
var rotation = Quaternion.LookRotation(lookPos);
rotation *= Quaternion.Euler(0, 90, 0); // this adds a 90 degrees Y rotation
var adjustRotation = transform.rotation.y + rotationAdjust; //<- this is wrong!
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

Easier solution:

transform.Rotate(Vector3.right, 90, 1);

Not sure if that’s correct in that Quaternion world (I really tried to understand, but that’s too complicated), but works for me.

“right” actually rotates 90 on X, thus pick which you need (up, back etc.)