I’m working on a 3D platformer that uses a Rigidbody for the character controller. I’m working on implementing moving platforms, but encountering some physics issues no matter what way I approach it.
I have a solution to apply relative velocity on horizontally moving platforms, adding the platform velocity to the player’s rb, and that seems to work fine and achieve the feel I want.
The issue comes in when dealing with vertical motion. At the apex of my moving platforms, the character is launched upwards slightly, even when making the player a child of the platform and explicitly matching velocity to the platform.
I am unsure what the best way to approach this is; I want the player to ‘stick’ to the platform, but with full freedom of movement to run and jump as they do on non-moving platforms. I’m assuming this is some result of using Physics, but unsure what the best way forward to resolve this issue is.
All my Rigidbodies are using Interpolation, all Rigidbody movement is happening in FixedUpdate.
Any help appreciated, and I can provide code and examples as needed.
In my own projects with moving platforms I used a transform parenting approach. It didn’t feel right until using the “Auto sync transforms” option under Project Settings > Physics > Auto Sync Transforms.
Try using kinematic rigidbodies for the platform and use Rigidbody.Move/Rigidbody.MovePosition to move it. In my experience, this improves stability of moving platforms with rigidbodies on top of them.
But part of what you’re seeing might just be physically accurate. When an object is on a platform moving upwards and the platform slows down, the object will retain the inertia and, depending on the weight and gravity, loose contact with the platform. You could try to tweak weights and gravity but that might not work with other parts of the game. You could also try to add a downwards force on objects on platforms, maybe only when the platform slows down. But you’ll have to make sure it doesn’t interfere with the player’s jump.
Making something is a child is irrelevant for physics. The physics engine only has rigidbodies, which are all simulated in world space. The transform hierarchy is bypassed when using rigidbodies.