# Rigidbody player controller on moving platforms

Game Development Asked by GoRgo 3 on December 13, 2021

So basically, I was trying to make moving platforms. When I finished my prototype, I noticed that the movement on the platform is very wobbly:
To snap the player onto the platform, I am just making it a child of the platform. Anyway, I don’t know what is causing this issue and was wondering if I can get any help. Thank you in advance

Here, the controller code:

private void Movement()
{
//Extra gravity
rb.AddForce(Vector3.down * Time.deltaTime * 10);

//Find actual velocity relative to where player is looking
Vector2 mag = FindVelRelativeToLook();
float xMag = mag.x, yMag = mag.y;

//Counteract sliding and sloppy movement
CounterMovement(x, y, mag);

//If holding jump && ready to jump, then jump
if (readyToJump && jumping) Jump();

//Set max speed
float maxSpeed = this.maxSpeed;
if (sprinting)
{
this.maxSpeed = 25;
}
else
{
this.maxSpeed = 15;
}

if(sprinting && y < 0)
{
this.maxSpeed = 15;
}

//If sliding down a ramp, add force down so player stays grounded and also builds speed
if (crouching && grounded && readyToJump)
{
rb.AddForce(Vector3.down * Time.deltaTime * 3000);
return;
}

//If speed is larger than maxspeed, cancel out the input so you don't go over max speed
if (x > 0 && xMag > maxSpeed) x = 0;
if (x < 0 && xMag < -maxSpeed) x = 0;
if (y > 0 && yMag > maxSpeed) y = 0;
if (y < 0 && yMag < -maxSpeed) y = 0;

//Some multipliers
float multiplier = 1f, multiplierV = 1f;

// Movement in air
if (!grounded)
{
multiplier = 0.5f;
multiplierV = 0.5f;
}

// Movement while sliding
//if (grounded && crouching) { multiplierV = 0.5f; multiplier = 0.5f; }

//Apply forces to move player
rb.AddForce(orientation.transform.forward * y * moveSpeed * Time.deltaTime * multiplier * multiplierV);
rb.AddForce(orientation.transform.right * x * moveSpeed * Time.deltaTime * multiplier);
}


I have had a nearly identical issue in the past. I solved it by making my Rigidbody kinematic while it is childed to the platform.

void Start()
{
rb = GetComponent<Rigidbody>();
}
void landOnPlatform()
{
rb.isKinematic = true;
}


This means that you will also have to determine when to turn the physics back on. It also has the major caveat of disabling physics on the Rigidbody while it is on the platform, but for my needs, this did the trick.

Answered by sirreldar on December 13, 2021