Is there still no simple solution for adjusting gravity direction?

By default, gravity in UE4 can be adjusted either positive or negative in the Z axis. Why hasn’t anybody put forth the request to change this float variable into a 3D vector variable (so that gravity can be set in any direction)?

EDIT: These are my findings so far (from a post I made below):

Probably never going to happen with the PhysX 3.3 physics engine and if it did go from 1 dimensional to 3 dimensional it would probably have a relatively huge performance impact

If you are lucky then the new Chaos physics engine will include it.

When I say “3D” all I mean is for the direction to be changed from the Z axis to the Y axis in real time (for example). Sure there are ways to fake this, but I need it to work on both vehicles and characters. And fake solutions will create a whole host of other bugs and technical constraints that wouldn’t otherwise be present.

I asked for custom gravity back in UE3 and early UE4. But it’s been done several times since by various devs. You could use the one here. Plugins & Tools - Elhoussine Mehnik

Thanks! That’s a great resource. But unfortunately I need a more holistic solution. The one you linked (as well as various others) usually only apply to a custom character movement component and an actor. I need the custom gravity to apply to everything in the world, globally. Thankfully, I downloaded the UE4 source code the other night and I’m already well on my way to implementing such a solution.

After looking at the source code I think it’s hilarious that global gravity comes down to an FVector setup like this:


FVector(0.f,0.f,GetGravityZ());

Had it been setup like this:


FVector(GetGravityDirection());

And exposed to blueprints (so that It could be changed in real time, which I’m currently in the process of doing) then this whole thread and countless others would be void.

It appears that you are correct that Unreal Engine has deliberately made gravity 1 dimensional. The more you know…

Definitely share this with us when you’re done please. You should be able to push your changes to your own github repo.

Definitely share this with us when you’re done please. You should be able to push your changes to your own github repo.
[/QUOTE]

I will see what I can do, although I assume that people before me have investigated the same thing and pushed the changes to EPIC only to be ignored.
Moreover, my solution would not be a plugin. It would involve users compiling UE4 from source which may put many people off.

Although I will post the code to my own Github repo!

However I’ve run into another issue on my PC that until it is fixed, I cannot continue my work:

Please share the snippet of the code, That could help others as well .

there is a custom gravity plugin that was free couldn’t you open it up and see how they did it? they made gravity for objects like spheres etc. I have no clue why you would want to change a gravity direction when you can use physics forces and all that.

physics forces don’t work the same as gravity direction or the effect of zero gravity in UE4. I already did look at the plug-in you mentioned and here is how it works:

The creator has made a custom pawn class that contains a custom movement component in which it has a gravity system independent from what ever UE4 is doing globally.
The problem with that plugin is that anything you want to make have gravity direction must be a “custom pawn” including simple objects such as traffic cones or crates. They all must be “pawns” in this system. This problem becomes worse when you realize that it is useless when it comes to vehicles. As vehicles in UE4 cannot be inherited from this custom pawn class.

oh wow. yea I didn’t think about cars. I have never used the plugin but seen it for free. sorry.

Did you tryed : Create an actorComponent that add force to the rootcomponent of the actor (disable gravity), Get the gravity from a c++ static FVector like this you can change it for the whole world. I have no idea about performance compare to the ue4 gravity system.

This should all be considered when the change from PhysX to Chaos is fully implemented. It’s obviously something people want from the engine, it’s a limitation that only has reasoning on the implementation level so can be completely avoided with a refactor, and let’s face it, this is only ever a relative sim-gravity as a sweep across the board anyway. It’s not real gravity so why not improve on it whilst the option is there? The physics code potential from real world to game level has definitely stepped up over the past couple of years to facilitate it.

Yes I’ve already tried this. Vehicles physics in UE4 are calculated using approximations and “forces”. The wheels on the car don’t actually spin. Therefore, “pressing” the car to the ground (or any surface) doesn’t behave as it would in real-life. This causes the car to not move because the speed of the vehicle is dependant on gravity approximations that are hard-coded into the Engine.

There is much more going on “under the hood” that I can’t summarise in a short comment, but to answer your question; Yes I’ve tried it, and no it doesn’t work unfortunately.

I couldn’t have said it better myself.

This sentence right here is one of the reasons why I started this thread. With games like Star Citizen (and many other space games such as Star Wars) having multi-planet gravity systems and local gravity on space-ships is only going to be more standard among games as the industry moves forward. For epic to not even acknowledge such a “simple” feature is a complete misstep on their part.

I looked at the latest UE4.24 and saw nothing has changed when it comes to the gravity system. So it doesn’t even look like such a feature is “in the pipe line” unless I’ve missed some something.

No problem, that plugin was one of the first things I checked out because I was so curious how they managed to pull it off. But so far in my search for a “real-solution” it seems that no code or plugin on the market actually attempts to fix the core issue of the engine. They are all just selling “hacky” ways to dance around the issue each with their own set of limitations.

Can you use the custom modified movement component that is available with custom gravity option. ? If that plugin gives you that component, it can be attached with other UObject classes as well

Unfortunately the custom movement component is not exposed to blueprints, So I cannot add it to anything. It can only be used via inheritance of a class.

Vehicles are piped through PhysX, it’s not a native implementation and barely anything to do with UE4 to be honest. PhysX is pretty much the staple physics engine for a huge quantity of games. All game physics engines are approximations and inaccurate.

I’d also strongly argue that games like Star Citizen are in no way mainstream or even common, and a multi-planetary gravity feature - or even changing the gravity direction at all, is extremely game specific. Non-fixed gravity directions in character movement means more netcode, at the very least more complexity. Most games have fixed gravity, and the last thing CMC needs is more complexity to satisfy a handful of games that would use this feature at the expense of all it’s users.

BTW: You can do a custom gravity implementation in PhysX if you like, just need to pass a flag to the PxScene:
https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/RigidBodyDynamics.html