Template - Walkable round planet with correct gravity

I’m working on a project in BGE where I wish to make a round planet that the player can walk on. Including proper respecting of gravity, and ability to use physical objects that still move accordingly. I asked for help on IRC, and someone was kind enough to make a full gravity script that would do all these things. Since this should be a useful and fun template, I thought I should post it here.

Features: Player can walk on a sphere and move in any direction (including both walking and jumping). Physical objects will still collide and roll around like they should. When viewing through the camera, the movement looks perfectly realistic and nothing looks or acts as “reversed”, keeping immersion intact. The script also supports multiple planets, and if the player could jump from sphere one to another, he would fall into its gravity range and be pulled toward that planet instead.

Credits: Script and blend file made by Jace Priester.


SphericalGravityTest.blend (431 KB)

Cool. I tried to make my own, but failed, so I’ll just snatch yours.

Straight forward and right to the point, the way it should be :smiley:

This looks very interesting, a lot for me to learn from it, thanks for the share mate :slight_smile:

Nice! I can make my own Mario Galaxy clone now :smiley:

So I got my guy working, but when I went in to make terrain things went wrong. He goes right through the hills, as if the planet is still a perfect sphere. Is it something in the script?

How I need to change the script to make this work on different objects using a property?

Yea how do you get multiple planets to work? I added another planet but script errors in console because line 15 or 16 World has more than 1 now.

Edit: So I figured how to do it, it requires the grav script to be attached to each object you want to gravitate and each planet must have a property named planet set to true and player must have a property nearPlanet


SphericalGravityTest.blend (464 KB)

Buna treaba!
Great job! That would be very useful.

Mersi / Thanks :slight_smile: I didn’t make the script itself, but I managed to make a game with it more or less.