Physics 360-degree rotation/movement inside a cylinder

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).

Thanks a bunch!

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.

That’s pretty good. I’m sure magnetism will come easily from this. Thanks!

Hey guys,

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 :stuck_out_tongue:

You might be better off not using physics simulation or Character movement at all, and instead write some custom movement yourself that only allows the pawn to move around the cylinder surface!

I’ve been thinking of doing that, it’s certainly much more easier to implement than modifying the physics.

The simplest way to do it is to set the pivot of the ship to the center of the cylinder, but eh… I don’t know.

Another way would be to do a constant AddForce, I’m thinking.

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 :slight_smile:

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

Sorry for digging up this thread again, but I can’t seem to figure out the movement.

Unfortunately, I’m running UE4 on an Intel G45 integrated graphics card, so I’m losing much of my patience through trial and error.

Can anyone help me out?

Could you maybe screenshot what you have and annotate it or draw what kinda thing you’re after and I’ll see if I can help with it.