I have a 2D platformer with each platform having a PlatformEffector2D component. I want to create a crate that can be pushed.

When I jump into the edge of the crate, my player gets stuck, so I added PlatformEffector2D to the crate. But when the crate has a PlatformEffector2D component it falls below the platform.

I can remove the component and add a Physics2D Material with zero friction to prevent the player from getting stuck in the crate's edge, but I can't walk above the crate (because the zero friction). The images below illustrate it.

Player getting stuck in the edge of the crate that don't have PlatformEffector2D.

enter image description here

If it has a PlatformEffector2D it will fall below the platform.

enter image description here

My objects have the following components (when the player gets stuck at the edge of a crate):

  • Player (BoxCollider2D, Rigidbody2D)

  • Crate (BoxCollider2D, Rigidbody2D)

  • Platform (EdgeCollider2D, PlatformEffector2D)

What should I do so my player can push the crate and walk above the crate? Would anyone happen to have a sample script?

FYI: I use Physics2D.OverlapCircle to detect the ground. (Unity 5.4.0)


1 Answer 1


Finally I fixed it. I added two empty GameObjects to check the right and left side of the player. Now he can push the crate and walk above it without being stuck at the edge of the crate.

// Check if player is on the ground or not
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
rightSided = Physics2D.OverlapCircle (rightSideCheck.position, groundRadius, whatIsGround);
leftSided = Physics2D.OverlapCircle (leftSideCheck.position, groundRadius, whatIsGround);

// Movement
if (!grounded && (rightSided || leftSided)) {
    // Do nothing
} else {
    // Handle movement input

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .