- Home /
How can I make a physics base projectile move along the path of a sphere?
My character sits in the middle of the screen, and when moving I rotate the planet to give an illusion that the player is traveling around the planet. However i need the player's bullets to wrap around the world when fired. So when fired the bullet will come right back around and hit the character in the back if the player stays stationary . The bullets are rigid bodies and pushed with velocity.
Example of what's going on. https://gfycat.com/gifs/detail/SecondaryDifferentInvisiblerail
What i'm trying to accomplish.
Answer by Glurth · Nov 28, 2017 at 09:15 PM
Based on the velocity and mass of the bullet, you can apply a force towards the center of the sphere, each frame. This is how orbits work.
(This would not put it "on-rails" though: That term usually means ignoring game-physics.)
To compute the force needed: from wikipedia https://en.wikipedia.org/wiki/Orbital_speed
V = Sqrt(GM/r)
V
will be the initial speed of the bullet. r
will be the distance between the bullet and the center of the sphere Solving for GM
we get:
GM = V^2 * r
GM
is part of the formula for gravitational force: F=GMm/r^2
Where lowercase m is the mass of the bullet.
Plug in our expression for GM
:
F= V^2*r * m / r^2 = V^2*m/r
So V^2*m/r
is the magnitude of the force you need to apply, towards the center, to a bullet of mass m
, for it to orbit at a radius of r
, moving at (linear) velocity V
.