- Home /
Physics platform character controller sliding issue NO parenting
Currently trying to make a physics character controller where it is self contained (you don't need to add scripts to ground/platforms that know about the character, you do not need to use parenting trick, etc)
There is a bug where once the platform stops, it slides the character off it.
I know this is due to keeping the old velocity from when platform was moving North lets say, but now its moving South.
But since my code is setting the players MovePosition to the platform+player, shouldn't this be reset even though the platform changed directions? or is it because MovePosition is setting a future physics update position? I'm a little baffled to be honest, I think I'm just missing some engine nuance or something here.
Not using built in character controller, all custom.
if(groundHit.collider && groundHit.rigidbody){
//TODO: bug where sudden stops launch character
maxSpeed = groundHit.rigidbody.velocity.magnitude + maxSpeed;//make sure max speed accounts for platform speed
Vector3 groundDirection = oldGroundPosition - groundHit.rigidbody.position;
Vector3 newPosition = rb.position + groundDirection * Time.deltaTime;//we want this but ONLY in grounds move direction
rb.MovePosition(newPosition);
oldGroundPosition = groundHit.rigidbody.position;
}