Quaternion Question

Hi everyone,

I’m currently working on a small game with small planets and faux gravity, it’s first-person and I’m currently working on the first person controller.

I’ve done all the main movement and gravity, but am not sure how to do one part: moving the mouse left and right rotates the player around it’s local Y axis, however I need to also make sure that the player’s y direction is always pointing away from the planet. So far I tried it by doing transform.up = (vector away from planet) however this changed the y rotation of the player.

I was wondering if anyone could give some advice on how to point the player away from the planet without changing the y rotation. Thanks lots!

I don’t really understand your problem, but there are two methods that you could check

Pass the inverse gravity vector as second argument.

Pass the rotation in angle as first argument and the inverse gravity vector as second argument

Don’t rotate locally. Calculate the world rotation with these methods and then set it to the transform

//pseudo code
float deltaRotation = GetDeltaRotationFromMouse();
firstPlayerRotation += deltaRotation;

Quaternion q = Quaternion.AngleAxis(firstPlayerRotation, -gravityVector);
firstPlayer.transform.rotation = q;
1 Like