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;
}
}