Best way to make custom gravity centers?

Hi there,

So I want to make a planet that has a gravitational pull on physical objects. PhysX however does not seem to support that kind of gravity, only allowing a gravitational force vector to be applied to all objects equally.

So I’m wondering what the best way to make it is then?

First Idea: just use “Simulate physics” on all objects that should be affected and then apply a force to their movement.
Issue: I cannot seem to figure out a way to apply a force or change the velocity directly in Blueprint. Not sure if C++ can do those.
Possible other ways/solutions:

a) Compute Velocity myself, Set new Location with Sweep=true for collision handling
Issues: Seems to get a bit messy if done with blueprint… might need a C++ implementation then?
Also sometimes my objects did not seem to collide… not sure there, might need to test more.

b) Use a Physics Thruster that gets pointed so it pushes the object towards the gravity center, simulating gravity

  • Did not test this yet but not sure how feasible and/or good this is…

It’s an optimisation, since in 99% of cases, people will want gravity to affect all objects equally. Otherwise, it’s just a linear force represented by a vector.

This should be fairly obvious; apply a linear force towards the surface or center of the planet.

Well I’m wondering what the best way is :wink:

And yeah that was my first idea xD However I failed to find the functions for it with BP… appears I have to use the StaticMesh instead of the Actor

any one can help? i really want to do this too!

Use your head :stuck_out_tongue:

If you want to use rigid body physics, you have to have a rigid body to apply physics to. Actors don’t have a primitive component until you add one, then you can apply a linear force to it - it doesn’t have to be a static mesh, just some kind of primitive component.

Dont think it is a “use your head” thingy :stuck_out_tongue: Of course they don’t have a body till you put something into them, but I already had a static mesh in them, so I just kind of expect the actor to have the physics velocity instead of the static mesh having it, since I see the actor as the actual object and the StaticMesh just being part of it. Since if i’d have 2 static meshes both with physics that would move differently, where would that place the actor, and such xD But it might also relate to the StaticMesh being the root object

Well it works for now~

I was thinking how to apply this, I was thinking to put an actor with a collision sphere which will make any actor that overlaps it apply a force towards the center.

Can also use a lerp to increase the pull as you get closer to the center of the sphere

Simply make a vector from actor to the gravity actor will that work or is there a better way?

Maybe have a look at Dynamic Gravity Actor Component on the marketplace?

Does your actor contain a Default Scene Root? You might want to try dragging the static mesh onto it, to make it the root of the actor. You can then set world transforms to move it closer to the planet.

Thanks for the replies! I will try this! :slight_smile: