- Home /
gravity inside sphere(not like mario galaxy)
Hi people ! Im really noob at game development and im having problems with the gravity in my game. What I want to make is that my players(multiple players son i cant rotate the sphere to solve the problem) can walk inside a sphere(Not outside like in mario galaxy....more like a hamster in a ball but without rotating the sphere)....so I need to make like all the surface of the sphere to have gravity or something like that ....i searched and didn't find anything....is this kind of gravity posible? apreciate any help thank you :D!
Answer by hathol · May 17, 2012 at 04:02 PM
What you want to do is basically taking some sphere gravity system ( nice explanations in that thread http://forum.unity3d.com/threads/15191-Walking-around-a-sphere-gravity ) and reverse it. So instead of getting pulled towards the center of the sphere, you get pushed away from it to the edges.
Your problem now is collision detection with the sphere borders. The most efficient way IMO would be to check the distance from the center of the sphere and restrict movement. Pseudocode would look something like this:
if(player.position - center.position < range)
ApplyForce()
else
RemoveForceOrDoSomethingElse()
thank you !! thats a really good idea :D it worked for me :))
if anyone is still interested in this: I guess it's more efficient to create an invisible torus and use the sphere gravity script with that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shuriken/ World Colider Problem Unity 4.1 - Particle just shown inside a Sphere 1 Answer
How to have a sphere roll/be affected by friction 0 Answers
Sphere with collider entering the flat surface 2 Answers
Cube starts shaking when placed on a giant sphere 1 Answer
False collision at the edge of hole when using high gravity value 1 Answer