Gravity in the Physics Engine

I have an open pull request to modify gravity within a Physics Volume. It is #376:Character and Projectile Gravity Override in Physics Volume”.

Currently, most people use Blueprints to accomplish its goal by keeping track of actors which enter and exit the Physics Volume. This pull request moves that functionality to properties of the volume, itself. It can add gravity, multiply gravity, or replace gravity with a specific value, positive or negative. It does not work on PhysX or Box2D objects, though. This would require some significant changes to the physics engine because it, currently, applies a single gravity value for the scene (although it allows the value to be modified on a per-frame basis).

Also, when discussing it in the IRC, people seemed a bit disappointed that it only worked on Z gravity. Apparently, some people want non-Z gravity.


Given that Unreal Engine 4 is a community project, I wonder how many people would be interested to, and participate in an, overhaul (of) the physics interface, altogether. This would obviously require significant community effort, especially if we want to make it backwards-compatible with existing projects (and we obviously do).

I had a couple of ideas:

  • For backward-compatible gravity overrides: Give each object a flag to override gravity. Also, give the scene a flag for “Custom Gravity” – which passes a zero-vector to PhysX’s default gravity and gives each object a gravity property.
  • For backward-compatible non-vertical gravity: Add a second parameter to gravity – a normalized vector for direction. By default, this would be (0, 0, 1) so that a magnitude of -980 would result in a gravity of (0, 0, -980), as expected.
  • With both, above points: The “normalized vector” for gravity could also accept an actor (or provide an actor to be placed) which will point to the physics object (as a means of driving the normalized gravity direction vector). Example: A point at the center of a large sphere drives a normalized vector from it to the physics object for radial gravity.

Of course, this will result in a large rewrite of CharacterMovement, the PhysX and Box2D wrapper, and so forth.

  • Would it be helpful to serious projects? Are there any, serious projects that would like this?
  • Also – can you think of any better methods or list potential (/definite) consequences?
  • Also – does this not go far enough? Is this too limited for the needs of your project? What are those needs?

Thoughts? Concerns? Comments?

I’ve been considering doing this myself so I would very much like to be a part of this if you decide to take it on. One of the things that has kept me from jumping in full-force is that a couple of necessary elements are on the UE4 roadmap: BodyInstance & PhysicsVolume gravity settings and arbitrary orientation/gravity direction for characters.

There were three main types of gravity that I was considering:

1) Vector gravity
Gravity as an arbitrary vector. This is standard gravity in an arbitrary direction. This would be the default with the vector as (0,0,1).

2) Point gravity
Gravity for the inside/outside of a sphere. This is where the gravity force on an Actor is a function of it’s location relative to a point in space.

3) Cylindrical gravity
Gravity for the inside/outside of a cylinder. This is where the gravity force on an Actor is a function of it’s location relative to a line in space.

I was also thinking about complex gravity fields (think running around on a Mobius Strip) but I don’t know if I want to tackle that yet.

Beyond the simple gravity physics, there’s also the issue of Actor orientation and player input that needs to be taken into account.

!! I need all of those. Almost all of my ideas for games would be greatly accelerated with vector, point, or cylindrical gravity. Even a pinball game would be much easier to layout if I could use vector instead of the limiting -Z.

I’m willing to help advise and test/debug for this - I have some experience with PhysX, though I haven’t tried messing with the gravity much, as it didn’t have the capability to set a per-frame gravity vector when I was using it at a low level.

I am extremely interesting in this! I’m all for it, but as of now, I’m not a coder but would be interested in helping out where I can.

Count me in. The coders I’m working with need it for a serious project. Of course, I’m only a 3D Artist :stuck_out_tongue: – but just letting you all know, there are people interested :).

This would be perfect for a project a few friends and I are working on. Being able to create a gravity effect in any direction by specifying an angle or a vector would be such an improvement.
You could achieve so much with this! I’ve been trawling the Web trying to find someone who’s achieved this and found one thread where they had gravity working in both the x and z axis for the player, particles and world objects but they didn’t leave any documentation or source code (copywrite reasons?) either way, this would be epic if you could pull it off.

Intergration in physics volumes is a must. I’m all for it, I really hope this happens!

It’s easy enough to do currently, but built in support out of the box would be nice.

The thing is, you’ll be working with PhysX, not the engine. I don’t think there’s anything in the Engine that specifically prevents other gravity types, but PhysX itself might not have support either, so you’ll have to go deep into nVidia code to do a lot of this too.

last time i looked at this, if i remember correctly, physx expects a vector. it is somewhere fairly early on in the engine code it changes from a vector to a float.
could be wrong but thats how it looked to me.
would definitely be a lot of work as gravityZ is everywhere but absolutely worth doing.