Issue with player landing on moving platform - Infinite Runner

I’m making an infinite runner game and have it set so that the platforms move to the left rather than the player moving forwards. My issue is that I have a platform the loops up and down as it moves left and when my player lands on this specific platform, they start bouncing off the platform, which isn’t what I want.
186749-123.gif

One way to solve this is by having the player as a child of the platform, which does work and stops the bouncing, but it also means that the player is then moving left along with the platform.
186750-456.gif

I know why this is happening as a child object will follow the parent object, but I can’t find a way to have my player act to not move with the platform without the bouncing issue.

The player has a rigidbody and box collider attached, the moving player only has a box collider.

Player jumping script:

if (Input.GetMouseButtonDown(0))
    {
        player_RB.velocity = new Vector2(player_RB.velocity.x, 20);
    }

Moving platform script:

private int moveVertical;

void Start()
{
    moveVertical = Random.Range(1, 3);
}

void Update()
{
    transform.position -= transform.right * (Time.deltaTime * 7);

    if (transform.position.x <= -20)
    {
        Destroy(gameObject);
    }

    if (transform.position.y < -2f)
    {
        moveVertical = 1;
    }
    else if (transform.position.y > 2f)
    {
        moveVertical = 2;
    }

    if (moveVertical == 1)
    {
        transform.position = new Vector2(transform.position.x, transform.position.y + 5 * Time.deltaTime);
    }
    else if (moveVertical == 2)
    {
        transform.position = new Vector2(transform.position.x, transform.position.y - 5 * Time.deltaTime);
    }
}

Can anyone offer a solution to this? I just want the player to land on the moving platform normally without bouncing or moving to the left with the platform.

Try setting the player velocity to right and equals to the speed the platforms are moving when he becomes a child of them and set it to normal speed (0 i think) when it is no longer a child

finjonathan’s answer would be what I’d try doing aswel.

Though I can’t help thinking a parent/child system could become messy, Did you ever try using FixedUpdate() instead of Update() on your moving platform?

Or possibly try adding a physics material on your 2D Rigidbody?


Make a 2D Physics material in your assets. Select it and make sure it’s bounciness value is 0 in the Inspector.


Then Select your Player in the hierarchy, and drag the 2D Physics material you just made into the material property of the Player’s 2D RigidBody Component.

@finjonathan

I’ve tried setting the velocity to right but it hasn’t worked unfortunately. I’m not moving my player, I’ve just got the platforms moving to the left so setting the players velocity to right results in inconsistant movement.

I tried setting the player velocity to a new vector2 and this kind of worked but the player starts jittering when landing on the platform.

@ricky_lee_

I should have mentioned that i’ve already created a physics material and set the bounciness to 0, but no luck. Also, using FixedUpdate for the platform movement made no difference either.

take an emptygameobject and attach the platform and another emptygameobject as child
attach a collider to the empty child;

move the empty game object(parent) and set the player as child to the child with collider.

dont set the player to the platform directly as child.