Ghost collisions problem: RigidBody player bounces, when moving on platform edges

Hi! I’m a beginner at Unity. In my first project I am trying to realize simple 2D runner game with mechanics of generating platforms one by one without distance between. The platforms are added by last position and reused, seems like all works fine.


Unfortunately, now I’m stuck with “ghost collisions” / “ghost vertices” problem.
The player sometimes catches edges of platforms and bounces. So “IsGrounded” property becomes false and player can’t jump. Platforms are located exactly next to each other.


I found the best visualization of this problem here (from 1:00). But I 'm not able to use tiles and composite colliders due to the fact that platforms should be generated randomly.


I can’t find working solution on forums. I already tried:

  • to play with different types of
    colliders (edge collider for
    platforms, circle collider for player
    etc.).
  • to add edge radius to box and edge colliders,
  • to play with project settings of Physics and Physics 2D (Default Contact Offset, Default Solver Iterations, Default Solver Velocity Iterations etc.),
  • to change player Collision Detection to Continuous mode,
  • to play with materials friction,
  • to change Update event to FixedUpdate for player (made it worse).

I found this code, but it didn’t help too.

private void LateUpdate()
    {
        if (transform.hasChanged)
        {
            transform.hasChanged = false;
        }
        else if (rigidBody.velocity.magnitude == 0 && !isGrounded)
        {
            rigidBody.AddForce(Vector2.down);
        }
    }

Also platforms have “Ground” layer and ignore collision with themselves (Physics 2D > Layer Collision Matrix). I was surprised because it didn’t help too. Why?


The situation has gotten better, but it keeps repeating sometimes. Maybe I used something wrong.
Is there any way to avoid this annoying problem? :frowning:
Thanks.


Additional information about last project version:

Player has BoxCollider2D with 0.1 edge radius.
Platforms have BoxCollider2D without edge radius.
Player and platforms have 0 friction material.
Player Collision Detection is in Continuous mode.
Default Contact Offset is 0.0001.
I use Update instead of FixedUpdate.

Two things come to mind:

  1. You use box collider - try to use sphere collider
  2. You can lift the current platform. Just try to create a simple script that lifts the platform when player is on for 0.01f or even less for instance. Yes, it is dirty fix, but may be it won’t be noticed if the value is tiny. OnTriggerEnter/OnTriggerExit can be used

The solution was to use adjacent Start / End points for platform EdgeCollider2D.
Explanation: Ghost vertices - Box2D tutorials - iforce2d