Unreal Z-axis independent gravity

It seems like UE and CryEngine assummed that no one will ever need directional gravity. Unity, Source and all the minor engines I worked with all do support it.

What are you trying to achieve?

This:

Look, I don’t want to come off as a huge douche, but I had really big hopes for ue4, invested plenty of time in it already and its perfectly reasonable to be annoyed at such artificial limitation.
Atleast theres source, but then I’m wasting time to implement something that was already there.

I’m just asking what you want in game? there might be another way of doing it…

I made a solar system in Blueprint, with orbital mechanics etc… so depending on what game you’re making, it might still be possible.

Point gravity, or atleast directional gravity that would affect rigid bodies, GPU particles and cloth.
Few people did it in UnrealEngine3 using forces, but this is not a solution for a large scale environment, since physics bodies won’t be able to go to ‘sleep’.
What he did, was checking if character collides with sphere actor and if it does, stop applying the force, but what when actors stops on something else, between reaching ground, or when ground is divided in multiple meshes with LOD.

Sorry guys I’ve not touched this really since the last update, I had been away from my job due to health which gave me lots of time to play with this. I’m now back at work full time so not getting a spare moment to touch this.

This:

For me this is a bit of fun and a showcase of what can be achieved. I can see that there’s a lot of frustrated designers out there that want to get their hands on this functionality so they can get to work designing gameplay and levels, but as much as it pains me I CANNOT contribute to the engine or share code. But if any programmers out there are attempting this for themselves, I will try to explain the fundamental changes I made.

Unity? From what I saw there you still had to implement it into PhysX in a super hacky way.

I don’t personally need it myself right now, but it would undoubtedly be a huge asset to the engine.

So my two cents are that it would be awesome if you could just do a rundown here about where you made your changes and a general sense of what you did, even if you can’t share your code directly.

For the record, Source doesn’t support point gravity either, though you can change the gravity vector.

Looks like we lost the last 3 posts on here during the maintenance… urgh mine was so long I can’t remember half of it :confused:

Sorry :frowning: We are putting processes in place to avoid this happening in the future. knocks on wood

Did you manage to get the CharacterMovementComponent to respect the gravity vector? It’s working for me as long as I move while in the air… otherwise, it zeros out all but the Z velocity, and I can’t seem to track it down.

Yeah I have the gravity affecting the player, I just don’t demo it in the videos so far as its not working correctly yet.

The first thing I did to get it working was replace this in CharacterMovementComponent:


virtual float GetGravityZ() const OVERRIDE;

With this:


virtual FVector GetGravity() const OVERRIDE;

You may have to edit parent classes too (I can’t remember been a while since I did it) and update all the references of GetGravityZ() to GetGravity(). Doing this should mean that all 3 components of the vector will be used instead of just the Z.

If you’re having trouble with updating all the references to use the new GetGravity() instead (this can be quite hard there’s a lot of Z dependent maths throughout the controller) I would just replace the tricky ones with GetGravity().Z for now until you can go through and rewrite all the math to be independent of the Z axis.

Just downloaded 4.5 and replaced every float GravityZ with FVector Gravity. Can’t wait to see what horrible bugs happen when the build is lol

I’m about to do the same for Space Dust Racing, fingers crossed! :slight_smile:

Surprisingly, it works pretty much like I expected. Character and boxes on example map all tumbled in the correct direction on startup. I’m rebuilding the character and input stuff now, and will add an iterator to wake physics bodies each time the world gravity changes.

Awesome, good to hear.

As far as I can see, there’s really no reason this shouldn’t be an engine feature. The amount of additional overhead is virtually non-existent - a few places using vectors instead of floats, and some extra functions to wake objects up when gravity changes, which it won’t unless you’re using this feature.

Please add this in 4.6 Epic! :slight_smile:

I think they are Trello

Well, rewriting movement component to use gravity instead of Z axis has been… difficult. I don’t understand what most of the functions in there are doing to begin with lol.

To be honest, I don’t know what a lot of the movement functions are doing but if you can identify where the Z based gravity was being used and what the math calculation was doing with it you can try to turn rewrite that little bit so that the calculation will work with a varying gravity direction.

Unfortunately I’m really busy at work so I’ve not looked at this for ages and won’t get to any time soon.

Well, there are places where it is obvious what is going on, like rewriting walkable floor to use the dot product of the floor normal and the inverse of the gravity vector. However, other stuff like UpdateFloorFromAdjustment(), I dont have a clue lol. I’ll take a look through the wiki and see what the intentions for all of these are at some point.