- Home /
Moving a Player Along With a Moving Platform Using a Physics Material
I have a moving platform that I've applied a rigid body and physics material to so that the player moves along with the platform as it moves. I tweaked the settings so that the player is able to move at a decent speed but it's still a bit slower than when on a non-moving platform. This slow down only occurs when the player is moving in the same direction as the platform. Moving in any other direction is normal speed.
I had the idea to set a trigger on the platform so when entered, it would apply an additional force to the player to counteract the gravity and increase the speed that the player moves. It's not working and I'm not sure if it's an issue with my code or my (lacking) knowledge of physics.
void OnTriggerEnter (Collider col){
if (col.tag == "MovingPlatform") {
// something to check if player is moving in the direction of platform
GetComponent<Rigidbody> ().AddForce (transform.forward * velMultiply, ForceMode.Acceleration);
}
Is this possible or should I do it a different way?
I'm not quite clear but from what can make out you probably need to make a new physics material for your moving platform and set it's friction to 0, and drag it into the physic material of the platform collider. so the player doesn't slow down when on the platform.
Hope this is what you wanted, if not could you attach a picture so i can understand what is going on better.
Answer by Mandraker · Apr 08, 2017 at 11:20 PM
Move character with transform.translate and disable character moves for forces on the platform.
Answer by SeahorsePro · May 05, 2020 at 09:30 PM
Try parenting the player to the platform when they enter the platform collider and unparent them when they leave.