Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concave polygon collision issue #596

Closed
paulcoms opened this issue Jan 22, 2025 · 1 comment
Closed

Concave polygon collision issue #596

paulcoms opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@paulcoms
Copy link

Describe the bug

Collision detection with polygons

A clear and concise description of what the bug is.

When using concave polys the collision detection system appears to apply to the concave space

Version

What version are you running?

v3001

To Reproduce

Steps to reproduce the behavior:

  1. Run in kaplayground:
// @ts-check

kaplay();

setGravity(300);

add([
    pos(0, 400),
    rect(width(), 40),
    area(),
    body({ isStatic: true }),
]);

add([
    pos(width() / 2, 100),
    polygon([vec2(0,0), vec2(0,20), vec2(40,20), vec2(40,60), vec2(60,60), vec2(60,0)],{triangulate:true}),
    color(RED),  
    area(),
    body()
]);

add([
    pos(width() / 2+40, 0),
    polygon([vec2(0,0), vec2(0,20), vec2(40,20), vec2(40,60), vec2(60,60), vec2(60,0)],{triangulate:true}),
    color(BLUE),  
    area(),
    body()
]);

Expected behavior

A clear and concise description of what you expected to happen.

I expected the polygons to only colide when they contact eachother

Screenshots

If applicable, add screenshots to help explain your problem.

Image

@paulcoms paulcoms added the bug Something isn't working label Jan 22, 2025
@paulcoms paulcoms changed the title bug: your bug here Concave polygon collision issue Jan 22, 2025
@mflerackers
Copy link
Member

That's not a bug, as the collision detection algorithm only supports convex polygons. You need to subdivide if you want to use concave shapes, or use a different collision library (though most of them also only support convex shapes, so you need to subdivide and add multiple fixtures).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants