# Check the entry point of a ship in planet's orbit and tell if movement is in rotation direction (2D)

I have a planet and a ship that orbits the planet. I have to check if the ship is moving in the same direction as the planet ships.
The planet has a random rotation speed and the ship can also move with different speeds.
How do i do that ?

/@iubisoft Basically you have to calculate the angular velocity of the planet and the angular velocity of the ship in relation to the planet. Here’s my test script which I used to calculate it. It’s signless. I can’t think of a way to resolve flying in the opposite direction at the correct velocity this tired so I’ll leave that up to you (maybe tomorrow :P):/

``````using UnityEngine;
using System.Collections;

public class ResolveSpeedenfp : MonoBehaviour {
public PlanetScript planet;	// Planet is a simple script which rotates a gameObject by speed * Time.deltaTime
public Rigidbody2D ship;		// Ship is a controllable rigidbody.

void Start(){
// This script was attached to a trigger gameObject with a parent gameObject holding the planet component.
planet = transform.root.GetComponent<PlanetScript> ();
}
public void OnTriggerEnter2D(Collider2D col){
Debug.Log ("Collision enter");
// I was having some difficulty with getting this function to work, you might as well ignore all this :P
try{
this.ship = col.transform.gameObject.GetComponent<Rigidbody2D>();
}catch{

}
}
Vector2 enfp;	// Extrapolated next frame position.
Vector2	prp;	// Position in reference to planet.

// Update is called once per frame
void Update () {
if (ship != null) {
// Additional gravity for testing purposes
//ship.AddForce((planet.transform.position - ship.transform.position).normalized * 2f * Time.deltaTime);

// This vector "extends" from the planet to the ship.
prp = ship.transform.position - planet.transform.position;
// This vector is the same, except we've added one frame's movement to it, extrapolated.
enfp = prp + (ship.velocity * Time.deltaTime);

// The angle between current position and next frame position should be a sufficient approximation of angular velocity.
float angVship = Vector2.Angle (prp.normalized, enfp.normalized);

// Angular velocity of the planet.
float angV = planet.speed * Time.deltaTime;

// The output of this debug log was quite convincing when the speed of the ship began to match the speed of the surface of the planet.
Debug.Log (angV.ToString () + "   " + angVship.ToString ());
} else {
enfp = Vector2.zero;
prp = enfp;
}
}
}

//Angular velocity is usually expressed in radians, but I'm using degrees/frame. (float angV = planet.speed * Time.deltaTime;)
``````