Help!, I can't make rotation work in update.

So, In this 2D game there is an astronaut player and there is a planet and what I’m tring to do is to basicly keep changing the rotation of the player so its feet constantly faces the planet’s surface but when I start the game it changes the player’s rotation z to 180 and doesn’t change it again even if the player’s position changes.

Here’s my code:
public class GravityControl : MonoBehaviour {
public GameObject Player;
public GameObject Planet;
Vector2 PlayerPosition;
Vector2 PlanetPosition;
Vector2 direction;

void Start () {

}

void Update () {
	PlanetPosition = Planet.transform.position;
	PlayerPosition = Player.transform.position;
	Quaternion rotation = new Quaternion ();
	direction = PlanetPosition - PlayerPosition;
	float tan = direction.y - direction.x;
	float angle = Mathf.Atan(tan);
	rotation.z = angle; 
	Player.transform.rotation = rotation;

	


}

}

The x, y and z components of a quaternion don’t have anything to do with it’s rotation angles directly, and you shouldn’t /needn’t ever touch them.

You should create a quaternion with the right rotation by using Quaternion.Euler(x, y, z) and perhaps a more comprehensive way to get the wanted rotation angle would be

Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

(On mobile. Cant test. Hope its right) :slight_smile: