Soft constraint to simulate gravity well

Looking for help with physics constraints.

I’m trying to make a constraint behave in the same way as linear / angular damping only wrt a rotating body (planet). Not looking for real physics here, just getting my player (and some other objects) to start moving relative to another moving object as they get closer to it.

I can lock my spaceship to the planet using a constraint, but this prevents it’s engines doing anything… rendering is a bit useless - am not sure how to stop this being a hard constraint and more of a soft constraint.

Updating the spaceships transform directly to the planets rotation works but causes all sorts of problems with the camera swing arm (which I could work around moderately easily) and then with the physics (much harder to work around with lots of likely longer term issues generated).

Any suggestions on a nice smooth transition from free movement to movement in relation to a planet are welcome!

So I gave up on using constraints. First tried a spring force to the sun, that worked but I was having some issues so I turned it into a spring force to an orbital track location. Turned out the issues were actually my models having offset pivots but the new math works pretty well.

Lol wrong answer. For the orbital mechanic I just apply torque to level of player space ships as they approach the planet, then I removed my use of Linear/Angular Damping and implemented my own that works in the frame of reference of the planet. Lastly I added a force to counter centripetal acceleration as you fly around a planet. End result is functional if not convincing.

Hello. I am wondering, could you please share more explanation, about ship leveling in reference to planet? Would much appreciate, Thank you in advance.

Yes and no! I’m happy to share but the solution was non trivial - and likely involves some combination of blueprint and custom C++ helper functions (though nothing you couldn’t implement in blueprint).

Also it should be noted that my end result isn’t great - my planets move quite fast and there are weird collision artifacts when you touch them. The real solution is for Unreal to add a concept of physics reference frames and allow us to move objects in and out of them. In past games I’ve worked on this has been critical to world cohesion - for instance a moving train with movable objects on it and people jumping on and off, interacting with the objects on the train and running jumping on the moving platform. Not a trivial problem at all but solvable with enough elbow grease. It’s possible that’s been added since I last dug around though…

Firstly I score my gravity wells, and only use the highest scoring well with a gravity factor of between 1 (at surface) and 0 (outer atmosphere - transition to space).

Then I use that to implement motion damping and counter centripetal acceleration.

The end result “swims” a bit.

Steps are:

  1. Add linear damping (relative to planet motion)
  2. Counter Centripetal Acceleration
  3. Add angular damping (relative to planet motion)
  4. Do any “make upright” mechanics you want

I don’t apply gravity to my objects - I don’t want them actually touching the surface of the planet because of the physics issues seen. Should also be noted that initially I was moving the planets by hand (setting velocity and position) which looked fine but led to really really bad collisions so I now move them with forces and torques.

tl/dr!

See attached zip with images of the blueprints used.link text

Definitely a few helper functions in those blueprints (like “get first physics component”) that you won’t have and only work because I know the objects created are pretty simple with a single physics component that matters.