Best approach for different gravity

Hello,

We are working on a prototype that requires the player to be able to walk on planets, and float in space when not in range of the planets gravity field. This means the gravity should be calculated depending on the characters position in space (And offcourse any other object with physics assigned).

Now the way UE4 handles gravity is a float variable on the Z axis that is set to -1. This can be changed to +1 or 0.5 or something. Also this is set on starting the game, and is not changed during runtime, and also locked on the map, and not different for every player. This is obviously not what we want to use. We have to create a whole new way of calculating the gravity for each player individually.

Now I did some research, and also tried some things, and I came up with 2 solutions. Either I am going to ignore the whole UE4 gravity, and put everything in the world to my own gravity calculation. But this would mean I can also not use the basic character movement and have to write it all for my own.

Or I could throw away the way gravity is calculated in UE4, and change it to the way I want. But this means changing the way the engine it self handles gravity, and could also be a risky approach (I think).

Any tips how this could be achieved in the best possible way? The project is not in a hurry now, and before breaking apart anything I would like some tips, and maybe someone here has done this already and has some ideas how I could do this.

Thanks in advance

You could always apply the gravity you want as an extra force on the actors. I’ll look into it further but thats what popped in my head first.

I recently made a pull request that does this.

You can call SetWorldGravity from the Level Blueprint with a vector and gravity for everything in your world will change to that vector.

If you only want the characters gravity to change, you can call SetGravity on it. You will still need to calculate the vector you pass to it based on the characters position in space, but thats all. (You will also need to adjust the camera and input controls to work for non-Z only gravity)

No problem. After answering this, I did some more research and found this plugin (link to actual plugin on first post of that forum) that appears to do everything the pull request above does and a little more.

Wow nice, initially I asked it for a small gamejam we did. But this could be helpfull for some future project :smiley: Thanks for the answer!

Thanks for the link! That is nice too :slight_smile: