- Home /
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.
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.
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.
Answer by finjonathan · Sep 27, 2021 at 02:26 PM
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
Answer by ricky_lee_ · Sep 27, 2021 at 03:21 PM
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.
Answer by gw707 · Sep 27, 2021 at 05:12 PM
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.
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.
Another idea is to not set that as a Child but instead if is Grounded set the vertical speed equal to the platform speed. Have you also set the material to the player and the platforms too?
Answer by SatansPineapple · Sep 27, 2021 at 09:37 PM
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.
Appreciate the suggestion but this hasn't work either i'm afraid. I still get the same issue as i get when setting the player as a child to the platform directly as mentioned in the initial post.
Your answer
Follow this Question
Related Questions
NavMeshAgent Not Working? 1 Answer
Player is Speeding up in collisions 0 Answers
Player boundaries based on screen resolution 1 Answer
i want to move a rigidbody using touch button 0 Answers
Cannot Rotate Player after Matching Camera Rotation? 0 Answers