Hello,
I am fairly new to Unity but trying to create a 2d platformer prototype. I am trying to get my player to ride along a moving platform and it works fine at slower speeds, however if I move the speed up very high there is a noticeable slide created by my player that I’m struggling to understand.
The current way the code works is I have
- A regular 2d sprite with box collider and a dynamic rigidbody 2d, moving by using rb.velocity in FixedUpdate
- A 2d platform that I move with rb.MovePosition in FixedUpdate and calculate the speed using
#PlatformMovement.rb
private Vector2 CalculateSpeed()
{
Vector2 currentPosition = rb.position;
currentVelocity = (currentPosition - previousPosition) / Time.fixedDeltaTime;
previousPosition = currentPosition;
return currentVelocity;
}
When my player lands on the platform their speed is set to the platform velocity as calculated above. There is no speed damping, and I am testing this without providing input so the player’s horizontal input should equal to the platform velocity. So where is this sliding coming from?
I’ve tried adding friction as well to the colliders but that does nothing. I also have logged the velocities and confirmed my player is always being set to the platform velocity.
Is there a script execution order I need to adjust or any helpful tips? I can provide more code if needed.