I am working on a 2D game, and I am working on adding some space physics : I need to find a way to create a circular orbit and an orbit like angry birds space ( the spiral trajectory ) . So there is 2 question
First Porblem :
I want to create a circular orbit, to make my game object move on a circular way around a planet, I am using the old famous formula :
V = sqrt(G * ((m1 + m2 ) / r))
This formula is the classic real world one, V is the velocity of the game object .
Once i code it, it doesn't move on a circular way, it just being attracted by the planet, like normal gravity . Here's my code (i'am using Unity 3D ) :
dist = new Vector2 (Planet.renderer.bounds.center.x - renderer.bounds.center.x, Planet.renderer.bounds.center.y - renderer.bounds.center.y);
r = dist.magnitude;
rigidbody2D.velocity = dist.normalized * (Mathf.Sqrt (0.5f * ((mBody + mPlanet) / r)));
Dist is a 2D vector and r is a float, The G value is 0.5 ( I used this one because 6.673E-11 is very small and it's not what i want )
So the question is is how can i make my gameobject move on a circular orbit like a satellite around earth ?
One thing to note, is that my gameobject is kicked by the player, so it get a speed of 12 . (i am using addForce() ) .
2nd problem :
I want also to be able to make the gameObject to be attracted by the planet in the same way of angry birds space or something like that, i need it to be attracted in a spiral way, which i can't find any ressource on the web to do that . I am using a simple code that use the Famous Gravitional law of Newton :
dist = new Vector2 (Planet.renderer.bounds.center.x - renderer.bounds.center.x, Planet.renderer.bounds.center.y - renderer.bounds.center.y);
r = dist.magnitude;
float force = 0.5f * mPlanet * mBody / (r * r);
rigidbody2D.AddForce (dist.normalized * force);
0.5 is the value of G, Actually this is a port of a code in C++ that'ive found on a BOX2D forum .
This work very well with attracting object, but what i want is that the gameObject follow an angry birds space like trajectory once it enter the gravity field of the planet :
So how can achieve a similar effect ?
Please explain in beginner friendly way if you answer , I don't have advanced physics and math knowledge (I am only a high school student ) .
Thank's !