# 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?

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
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!

1 Like

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