Quaternion.LookRotation() is...wrong?.. well at least unclear

Hi all,

I’ve been struggling to get my bullets to point in the correct direction. Take a look at this;
I have used Debug.Draw to draw the new Forward direction in Blue, and the Up direction in Green.

However, when I pass these exact same variables to the Transform.LookRotation() function, the actual rotation is not the same one (as can be seen by the gizmo in the screenshot above).

I would expect the object, and Gizmo, to actually be rotated in the calculated forward direction, but it’s somehow orthogonal to it. So for some reason, LookRotation does not in fact look at the direction!?

Now, I realize that this function has been here a long time, and I’m probably just missing something as a Unity newbie. But what?

Help please :slight_smile:

Using Unity 2020.2

Your up and forward vectors are position vectors, not direction vectors. You’re normalizing them, but that’s just making them up and forwards vectors for the origin, not your energy ball thingy. You essentially want LookRotation(newForward, transform.position.normalized):

// rotate along tangent of planet
var up = transform.position.normalized;
var forward = newForward.normalized;

Debug.DrawLine(transform.position, transform.position + 100f * up, Color.green);
Debug.DrawLine(transform.position, transform.position + 100f * forward, Color.blue);

var lookDir = Quaternion.LookRotation(forward, up);
transform.rotation = lookDir;

I think that should do it.

1 Like