So my goal is a little 2d Brawler, where you can go around the world fighting bad guys. The world is shaped as a sphere, and players can walk around the globe.
I’m using a fake gravity system to keep the player grounded onto the planet.
I’m pretty lost as to how to handle Jumping/Flying at this point though. Just trying to get a jump button working using Addforce, the player character will often get pushed backwards, or will just slide backwards along the ground. Any ideas as to how I could implement a jump/fly mechanic on this sphere world?
Firstly, that’s a circle, not a sphere. Spheres are 3D, circles are 2D (well, technically they’re 1D, but that’s beyond the scope of what I’m getting into, here…). There is no third dimension in that game, and if you had the characters able to walk over a sphere, it would be a 3D game.
Proper terminology aside, the biggest issue you’ve got here is that you want to have a gravitational center rather than a gravitational direction (which is how Unity’s gravitational system works). The first thing you’ll want to do to fix this issue is to ensure the “use gravity” boolean on all the rigidbodies you’re using is set to false (or “off”).
Next comes the more challenging part: You’re going to need to somehow manage all the objects that will be affected by gravity to have force applied to them (or their positions altered, in the case that their rigidbodies are kinematic) such that they are pulled toward the center of the circle being used.
Now that the gravity is out of the way, you’ll need to ensure that the rotation of the objects is correct, with respect to the center of the planet. To do this, simply find the angle at which the objects are at, with respect to the planet’s center, then find the angle that is perpendicular to that angle (Hint: Add or subtract 90 degrees, or pi/2, if using radians :P).
You’ll have to recalculate the rotations each frame (or at least each time their angle with respect to the planet’s center is changed).
the simplest way i can think of is to use some vector maths if you do for gravity rigidbody.addForce(Gravity*mass*Vector3.Normalize(planet.position-transform.position));
note that gravity is whatever force you want per mass so earth is 9.81 N/kg