Can I change the gravity direction?

I know that I can invert the gravity to a negative value but what if I wanted it to point forward or backwards, left/ right? Also is there a way to do this in Blue Print?

1 Like

I have done that by overriding UE4’s gravity and creating my own. How?

I have certain stuff in my game that I want them to react on directional gravity, all of them are child of my “Obstacle” blueprint. This can be done in other ways in your case but I’ll show you how I did it :slight_smile:
This “parent class” has one Vector3 variable “Force” and one colider with one value changed - Physics → “Enable Physics” turned off (you need to click the small arrow down to unfold advanced settings if you can’t see it). That prevents an object from being affected by standard one-value ZGravity of UE4. Of course “Simulate Physics” mustbe checked for the rest of physics simulation to work.

Next, in the events graph just run “SetPhysicsLinearVelocity” function every tick, so you can easily manipulate that value in the runtime:

Using this method you can try setting linear velocity to a variable in the Level Scope, so all object share the same value.
Hope that helps!

3 Likes

Hello Thumper,

What exactly are you trying to accomplish? Are you trying to change the gravity for the Player Character, a certain actor, or all actors in the level?

Thanks,

~Sam

Well I’ve looked around looking for a blue print solution to creating inverted point gravity. So, in stead of gravitating toward a point like a planet you would repel from it. Imagine a hollowed out world where you can run around the inside of a sphere. This looks impossible through blue print only. But maybe there is trick. First I need to figure out how to point gravity in a specific direction. Currently the only access I see is in the character movement component. Where gravity z can be valued to a positive or negative. I was hoping for more of a vector or direction. Now it’s got me thinking of crazy super hacks that I know will only cause serious headache down the road.

Rotating the world around the player is extreme, plus there’s no way to get a navmesh to produce on the walls or ceiling that I know of. So the navmesh would have to create dynamically on the fly (which I’ve read is possible to do but sounds scary considering the scale of my navmesh requirements).

Check my other answer to see how I overriden standard gravity. Vector3 is available but you might want to do some more math to figure out how to make player walk “inside the sphere”. Maybe figure out the direction from the center of sphere towards a player position and add that as linear force on character. Then you would need to rotate character accordingly.

Yup, It’s fake gravity indeed. I couldn’t find any other proper way of doing this. UE4 doesn’t seems to provide gravity as vector.

This is something I’ve been considering. So you’re saying to use forces to drive them in the direction instead of gravity? I think this is a possibility.

Can physics objects sleep this way? Or are they simulated all the time?

I tried doing this method but I ran into issues with getting the physics objects to not freak out during most other situations. Instead now I’m just programming the way the Character Movement Component uses gravity (modifying the evaluations/ velocities to use the character capsules Up Vector instead of the world “Z” axis). It’s a bit of work but I’m already seeing the advantages - one big one being that I can keep the Character Movement Component with all it’s robustness.

That is a good question. I’ll remember to test it…

Hello All,

This is a very popular subject that currently has no built in solution in UE4 to support gravity in any other direction that -Z. The possibilities are endless with direct access to the source code though!

There is a very interesting post on the forums Unreal Z-axis independent gravity - Game Development - Epic Developer Community Forums with someone making great improvements on his own project. He also raises good points about the different types of gravity being vector gravity volumes, point gravity, and inverse point gravity.

Good luck!

~Sam