Problem with setting transform.up away from object

I’m making a game where the player can walk around a “planet” in 2D by setting transform.up to the vector from the player to the centre of the planet. This works for the most part, but when the player is facing downwards it gets stuck and starts to rotate wierdly. Is the problem that i should be using Quaternions or is it something else? Does anyone have an explanation on how in that case?

PlanetVector = ((Planet.transform.position - transform.position).normalized) * -1; transform.up = PlanetVector;

Well, a common solution is to just use FromToRotation and specify the current up vector as “fromDirection” and your target up vector as “toDirection”. This will result in a relative rotation that you should apply to the current orientation.

var rotateUpwards = Quaternion.FromToRotation(transform.up, PlanetVector);
transform.rotation = rotateUpwards * transform.rotation;