# 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

## Related Questions

### MouseLook Script “Pops” back to the last value when the script is enabled after being disabled or destroyed

1  Asked on January 7, 2022 by cyo

### Unity app crashes when using unmodified custom Android manifest (didn’t find class “UnityPlayerActivity”)

1  Asked on January 7, 2022

### How do i draw a ray in unity

1  Asked on January 7, 2022 by levent

### Unity get reference of GameObject under another GameObject

1  Asked on January 5, 2022

### testPoint not working – libgdx

1  Asked on January 5, 2022 by ngc-qu-nguyn

### C# Increase move speed for spawned objects

1  Asked on January 5, 2022 by jenkatan29

### How to make Rigidbody.AddForce less delayed in Unity3D?

1  Asked on January 5, 2022

### How Client send info to Host in Unity Multiplayer

1  Asked on January 3, 2022

### I accidently changed the cursor image in Unity

1  Asked on January 3, 2022

### Changing ImageView position based on angle of rotation

1  Asked on January 3, 2022

### Rotate vector by matrix?

2  Asked on December 29, 2021

### How to render a large, seamless platforming world without scene transitions?

2  Asked on December 29, 2021 by homo-sapiens

### New Unity version copies the settings of previous version

1  Asked on December 29, 2021

### Unity animation transition with 0 Exit Time doesn’t transition immediately

2  Asked on December 27, 2021 by sonny

### How can I find the offset rotation and position between two objects in 3D?

2  Asked on December 27, 2021 by mahmoud-sagr

### How to implement the “technological tree” drawing?

1  Asked on December 25, 2021

### Finding all possible paths from one hexagon to another

3  Asked on December 25, 2021 by vitozz_rdx

### Unity : apk vs aab for the same scene

0  Asked on December 23, 2021

### Unreal Engine custom camera

0  Asked on December 23, 2021

### (Tiled) Background stops being rendered in libGDX

1  Asked on December 21, 2021 by xmac

### Ask a Question

Get help from others!