Unreal Z-axis independent gravity

Lastest Progress

  1. Basic gravity implementation
  2. Gravity support for particles
  3. Gravity support for physics objects

Hey guys,

As the thread title suggest, I’ve been working on adding support for z-axis independent gravity. I just wanted to show off :stuck_out_tongue: 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.

Video 1 - Basic dynamic gravity and CPU particle support

=

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.

Video 2 - GPU particle support

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.

1 Like

Had followed your other thread. Great stuff.

Cheers, gonna look at making sure all physics objects are woken when the gravity is altered next.

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.

The movement controller math needs to be rewritten for z-axis independency but yeah it should be doable.

Nice work! Keep it going :slight_smile:

I really hope this gravity thing will be possible to use in projects like UT4.

[

=

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.

Its a shame you cant share the source code… at least can you tell me which files did you modify?

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 :slight_smile:

Kickass!

I love games with non-generic gravity :slight_smile: 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.

Thanks :smiley:

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.

Oh yeah

World machine, world machine, world machine…

=uRRx_Bep1ic

Seriously what you are doing is awesome, I will model you a world machine if you need one :smiley:

[HR][/HR]
Some other links
http://isaac3dart.blogspot.com/
https://www…com/user/isaac3dart

Thanks man, it’s just a bit of fun for me in my spare time, we’ll see where it goes any way.

P.S I could probably mock that up in a level with some blueprint work :wink:

Hee hee your welcome!

I really like that in-game rendered chart you made to show which way gravity is going! This should become a real UE4 Example Content demo!

:slight_smile:

Rama

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… :frowning:

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.