Object's rotation depending on a ray

So I have a planet and a starship flying around the planet (2D), and I want to rotate the starship 90 degrees as it hits the planet, so it would look the way it should. I have a ray which goes from planet’s center to the starship so I want to make a 90 degree angle between the ray and starship’s rotation. And starship.transform.rotate(0, 0, 90) wont work because it may hit the very side of a planet and so the rotation will be wrong, I have to update the rotation of a starship every frame too. Any suggestions?

31466-asasds.png

Let me start by getting your ship pointing in the correct direction. First, I want you to edit your sprite so that the front faces right when the rotation is (0,0,0). Then you will change your code as follows:

So you have:

 up = transform.position - satelliteCenter;
 dir = Vector3.Cross (Vector3.forward, up);

Rather than LookRotation, I do the following:

 float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);