Trajectory of ROCKET flying away from a planet
I have a sphere with attached empty object, the object is on the planet's surface, rocket launches from this empty object. Sphere is rotating.
My rocket can fly by spiral trajectory from a center of it's instantiating place. The problem that I can't resolve is that rocket's trajectory is independent from planet's rotation.
This is Update() function for the rocket:
void Update () {
angle += speed * Time.deltaTime;
x = Mathf.Cos (angle) * radius;
z = Mathf.Sin (angle) * radius;
rb.velocity = new Vector3(x,0.0f,z);
radius += stepOfRadius;
}
What I have:
How I want it to be (without moon and returning back to Earth):
Answer by Erethan · Feb 15, 2016 at 12:50 AM
You should consider to emulate gravitational force on the rocket instead of mathematically modelling a trajectory. Even if you manage to model it, It's path would be quite artificial and might be hard to make it flexible for different planets or rockets;
1)Add an initial velocity and a direction Vector3 for the rocket
2) Apply gravity force from the planet
F = (G m1 m2) / (r * r);
Where G is a constant that you should tweak to get the right feeling, m1 is the rocket's mass (may be even ignored), m2 is the planet's mass, and r is the distance from the rocket to the planet.
Do somehting like:
rb.Addforce(F * (planetTransform.position - transform.position).normalized,ForceMode.Acceleration);