I’m not sure if I posted this in the right forum, or if I’ve titled this thread correctly, but here’s the deal.
Back when I was using UDK, I was trying to make a game in which your ride a nondescript vehicle through a perfectly shaped cylindrical tunnel. The catch is that you can move forward through the tunnel, and you can also rotate your ship on the tunnel’s inner surfaces.
The thing was, I got stuck trying to trick the UDK physics into changing the gravity.
Seing how UE4’s physics engine is exposed, is it possible to do this? If you’d like, you can think of it as a magnet that holds the vehicle on the inner surface of the tunnel (a feature being that you can detach from it and float inside it).
You can take a look at it in the source. However, it is hard-coded as “GetGravityZ()” so, as you can imagine, gravity can only be up or down.
Someone on this forum was already trying to convert this to a vector so you could set the global direction to whatever you wanted. With a quick search you can likely find the progress he’s made on it. (Edit: link)
Another solution would be to simply disable global gravity (or ignore it for your player), and apply a custom force to simulate gravity on the player. You will also need to rotate the player to align with your custom gravity, but that should be fairly trivial. Your gravity won’t be global (i.e. it won’t affect particles or other objects), but that may be closer to what you want in your case anyway.
With regard to the link to the other thread, I’ve got that hard coded Z gravity all swapped out for a vector already, its not too hard to do.
However, the character controller is a different kettle of fish. This is the the class that will manage the behaviour of your ship while it’s in its magnetised attached state. It will also control it while it falls unless you make it fall with the regular physics system. The problem here is that all the math for dictating the movement of the player is done on the basis of the gravity being hard coded in the z axis.
I’m going through it all at the minute rewriting all the math in my spare time but its gonna take a while as I’m not a math wizard
If you did the constant force you would still want to write some thing that looked after it once it hit the surface of the cylinder, pushing it against it every frame with a force would cause issues. I’d go with what James suggests
what about attaching the ship to a sphere, with a rigid body constraint (like a hinge that is free to move along the cylinder’s axis)? you get to keep the advantages of rigid bodies without worrying about gravity (just turn it off?)