As the thread title suggest, I’ve been working on adding support for z-axis independent gravity. I just wanted to show off what I’ve managed to do so far and hopefully keep it going as a hobby for myself in my spare time.
Unfortunately, my circumstances don’t allow me to share the source code so please don’t ask. However, I am more than happy to point people in the right direction.
Currently I’ve only really some basic stuff and added support for particles, I’m looking to add character movement support and also to support gravity volumes.
This was a basic update to the engine replacing the gravity float value in WorldSettings to a vector and then going through the rest of the engine and replacing any instance of a hard coded gravity in the z-axis with the new vector from WorldSettings.
I also begun updating the particle systems engine as it was 1 of the first things I noticed that did not support dynamic gravity, managed to get the CPU particles working relatively quickly for this.
This update shows that it is possible to support dynamic gravity with GPU particles too, this involves updating shaders and code that works on the GPU.
Neat! Do you think it would be difficult to expand this and make the FPS controls flip? Do you know the game Prey? They had walls that you could walk up and ceilings that you could walk on.
In this video I managed to get all physics objects to wake up on the world gravity changing. The HUD in the top left shows the current direction of the world gravity, the centre being zero gravity.
Take a look at this tutorial (thanks Rama). These iterator objects are useful in searching through all instances of an object or actor within the world.
I used an Object iterator to iterate through all the static mesh components in my world.
TObjectIterator<UStaticMeshComponent> MeshIter;
Using one of these you can iterate through all the static mesh’s with a loop anywhere in your code, place it somewhere that ticks each frame and where you can query the current gravity and check if its changed.
Then call WakeAllRigidBodies on each static mesh to kick in their physics simulation and that’s it
I love games with non-generic gravity Thanks for pushing the engine in this direction!
One of my Epic Friday projects was creating a Lunar Lander game where you had to land on a moon that was a sphere so you could orbit it first, etc. At some point I would love to see a game that is on the inside of a sphere so gravity is outwards.
Hopefully I’m gonna be able to expand this implementation with gravity volumes and point gravity, so an inverse point gravity in the centre of a sphere should work for that concept.
How is it going? Any chance we see it in engine or atleast see the code?
I am really suprised gravity is hard-coded for single axis. Imo strange decision.
I can’t continue my project without it. Nasty hacks are not an option.
In my opinion constantly applying impulses might slow down execution and make the game buggy. Do physics objects go into sleep mode? If so, then it will decrease performance alot.
Now I have to either abandon ue4 completly for this project or try to recreate what mwadelin did. None of these make me happy…
In the vast majority of games, Z is down, or in rarer cases like space sims, there’s no gravity at all. Games which have multi-directional gravity are very much an exception rather than a rule.
Single axis gravity is a fairly solid optimisation, and I expect most game engines do it - certainly the big ones do. There is however nothing stopping you from downloading the source and implementing your own vector based gravity system. In Mwadelin’s case, it looks like he’s updated gravity to be a vector and has the ability to update it on the fly.
Awesome work - just a shame it can’t be contributed back to the engine somehow. Variable gravity direction is something hardly ANY engines support out of the box. Not to mention being a big pain to implement well.