1
votes

I've some trouble with my moving platform.

I'm working on a 3D platformer game, my player has a rigidbody attached to it, and I use rb.MovePosition() for movement.

My platform has only a box collider.

I use the standard parenting method to make my player stay on the platform :

protected virtual void OnCollisionEnter(Collision other) 
{
    if(isPlayerTag(other.gameObject.tag))
    {
        other.transform.parent = transform;
    }
}

protected virtual void OnCollisionExit(Collision other) 
{
    if(isPlayerTag(other.gameObject.tag))
    {
        other.transform.parent = null;
    }
}

Here's my issue : when the platform doesn't move, my player can freely move on the platform, but as soon as the platform moves, my player is stuck on it until the platform stops.

I use FixedUpdate() for both movement.

For the platform :

protected IEnumerator PlatformTranslation()
{
    
        float movementPercent = 0f;

        while(movementPercent < 1)
        {
           movementPercent += Time.fixedDeltaTime * platformSpeed;
           transform.position = Vector3.Lerp(startingPosition, nextPositions,movementPercent);
           yield return new WaitForEndOfFrame();
        }

}

Thanks for reading me !