Dynamic gravity for characters

Hello Guys,

I know all here have many Projects and Work but us hopeful that anyone can help us.

We are an Academy for 3D Artist in Germany and like the Projects on our Students make alive to show up for the Gameindustrie.
We are no Programmer so we need help to create Template(s) to create good Portfolios for our Students.

We need for a Jump and Run Template for a Portolio to let the character run in a loop (like Sonic), we are no Programmer / Coder.
Also, we need exactly a Guide / Tutorial to Implement or a other way to do it.

Can anyone help us please.

Thank for share all you Knowledge on Forum you are really great community!!!
A Special thanks to for sharing code

Any for re-upload code?

The code is Avalible on Github (u need only add EpicGame to you Account!)

same here but where to Compile it? isnt for Version 4.8 right?

Sorry if is a noobish question, but how do I now use that updated code?
At the moment I do a line trace from my character to the center of an object (in my case a sphere). I understand that I need to break the hit > get the normal > reverse it, but what do I do then? I’ve tried plugging that result into the Set Gravity Direction node but that’s not giving the desired result. I read something about applying a rotation to the CapsuleComponent of the character?:confused:

I think you’d help out alot of people if you’d explain how to use logic in blueprints.

Thanks in advance!

Part of the code already been merged in 4.9 branch, and reset supposed be in 4.9 according to ZakMiddleton ().

I’ve ported the code to 4.8, tested and all works fine. I can put them to github if anyone interested.

I’m trying to use in 4.8, can you put on github? thanks

1st post updated:

[hr][/hr]

The code you quoted takes floor normal (if there is any) and changes gravity direction each frame, so it might ignore any use of the “Set Gravity Direction” node in blueprints.

is great, and very fitting music for the video :slight_smile: haha
Good job.

I try to update client to not fall, but with no result yet :frowning: It seems gravity scale and rotation works but not movement direction :frowning: Anyone can help me with ?

I am very confused because on client there is 4x more code executing. It seems server run his own gravity code with different gravity direction. That’s why even with no gravity client jitters.

When I remove ReplicateMoveToServer gravity works fine, but I need replication so I am working on it. Right now it works OK but adding forces so my character is all shaking. Playable but I want to get rid of mystical force and try to make simple replication. Any ideas?

Anyone has idea how to replicate moves?

is great!!! Unreal must implement !!! Hope we c an see the results by the end of the year

So, the update in the OP seems to suggest that is being merged into the Core UE4 codebase. sounds awesome! Any news on if/when will be done?

There isn’t a solid timeframe, according to Epic.

Tefel, chech your PMs.

I have no idea how to implement into my build of UE4.
I’ve downloaded 4.7.6 source from github. I’ve changed the code.
When I build it gives me almost 100 errors.

If there’s anyone who could lead me through the proces, explain like I was 2 year old child, how to do that, I’d be grateful… PM me maybe. Thanks.

I have some ideas for .

First, we have to think big. As in planetary bodies. Gravity should be treated as a force vector, proportionate to a mass ratio of a physical body (such as earth). The amount of gravitational force applied to a body is something like an inverse square law of its distance from that object (I’m sure a good physics book has a precise equation). If you have two bodies which exert gravitational forces on an object (such as the Earth and Moon), then to find the gravitational force vector applied to an object, we’d have to go through all gravitational forces, figure out the gravitational force from distance X towards the center position of each body, and come up with a sum of gravitational forces vector. force vector can then be applied as an acceleration force.

Optimization:
I think that may get computationally expensive with a lot of gravitational bodies, especially if they’re dynamic. I think that if you at least have a bunch of static gravitational bodies, you could go through chunks of 3D space and pre-generate a vector field which would suggest the sum of all gravitational forces at some position. The gravitational force applied could be determined by which cell you’re occupying and then querying its gravitational vector, and then applying it to the bodies in that field.

The “up” vector is an interesting one. As far as cameras are concerned, I’d keep the game model up vector unchanged, regardless of gravity because it keeps rendering consistent. But the “up” vector which suggests an up orientation could be set to the normalized inverse of the gravitational force vector. Jumping would cause an impulse force on vector (etc, etc).

Late to the feast, but wow looks incredible! Any pointers on where I can get my hands on the code and play around with it?

Hi, I’ve been adapting the code to the 4.9 version, I spent some hours on doing it ( is my first modification on the ue source code) and I want to share adaptation with anyone who wants (and, like me, cannot wait to epic to implements it).
I think there are some bugs, but it works well on my side scroller game. I will do some improvements on the next days

cpp: CharacterMovementComponent (GravityVersion UE4.9) - Pastebin.com
h: CharacterMovementComponent (GravityVersion UE4.9) - Pastebin.com

Also, really thanks to for doing , you saved me a lot of work :slight_smile:

So, can I download 4.9 source from github and just replace the flies? Will that work? Didn’t work with 4.7.6.

Yes, it should work, I just pull the 4.9 last thursday and only have modified that two files.