Player on moving Platform isn’t moving with it.

Hi, I am relatively new to Unity and making a small 3D game where I want the Player-Character to be able to step onto a moving Platforms to get from one point to another. The Platforms move between two empty game objects but don’t rotate or scale. The Platform itself is an Emptry game Object with a Collider and the Script that moves and Detects the Player. It has a Child which is the Model of the Platform itself. The Player Character is Tagged as “Player”.

I have tried to move the player with the platforms using this code:

private void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        other.transform.parent = this.transform;
    }
}

private void OnTriggerExit(Collider other)
{
    if (other.CompareTag("Player"))
    {
        other.transform.parent = null;
    }
}

I first tried it with the ThirdPersonController(Ethan) from the “Standard Assets 2018.4” Package and it worked fine. I then made my own Player-Character with Animations from Mixamo following this tutorial:

The new character gets turned into a Child of the Platform when standing in the Box collider of the Platform but only the Rotation of the Platform gets applied (which didn’t happen with the Ethan Controller and I don’t want it to happen) and no movement change at all happens.

I have tried for some time now to get it working but I have had no luck so far.

I would be really happy if anyone could help me with this.

I’m assuming that your player script is overriding the player’s position, which will cancel out any movement coming from the platform. You will need to adjust your player script to take into account if you are currently on a platform.

A reason for the player as a child of the platform not moving with the platform in your case is the option “Apply Root Motion” in the Animator. I am not sure about your configuration and if this fixes your issue entirely (at least it worked in my test scene), but try turning it off/on when the player enters/exits the Collider.


    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            other.transform.parent = this.transform;
            other.GetComponent<Animator>().applyRootMotion = false;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            other.transform.parent = null;
            other.GetComponent<Animator>().applyRootMotion = true;
        }
    }

If you do not want to do this (not sure if this has any unwanted side effects), a possible solution would be to translate the player according to the movement of the platform in addition to any input movement instead of parent/child movement.