rapier icon indicating copy to clipboard operation
rapier copied to clipboard

(Help Wanted) Using Compound Shapes with Triangles Produce Undesirable Collisions

Open msparkles opened this issue 2 years ago • 0 comments

This is the code I'm using to generate a collider with compound shape.

fn get_collider(
    nodes: &HashMap<String, Node>,
    attributes: Option<&Attributes>,
) -> Option<Collider> {
    let path = tessellation_single(nodes.get("collider")?);

    let vertices: Vec<RapierPoint> = path
        .vertices
        .iter()
        .map(|v| point!(v.position.x, v.position.y))
        .collect();

    let shapes: Vec<(Isometry<Real>, SharedShape)> = path
        .indices
        .chunks_exact(3)
        .map(|v| {
            (
                Isometry::translation(0.0, 0.0),
                SharedShape::triangle(
                    vertices[v[0] as usize],
                    vertices[v[1] as usize],
                    vertices[v[2] as usize],
                ),
            )
        })
        .collect();

    if let Some(collision_group) = attributes.and_then(|v| Some(v.collision_group)) {
        return Some(
            ColliderBuilder::compound(shapes)
                .collision_groups(collision_group)
                .solver_groups(collision_group)
                .build(),
        );
    }
    Some(ColliderBuilder::compound(shapes).build())
}

Here, it's using triangles tessellated from an svg element, using lyon, which is a rectangle (for now. The rectangle is just a simple placeholder). The final result is a shape of 3 triangles.

And it doesn't work perfectly. Why?

image image

(*One of the triangle is barely visible because it's overlapping with the actual entity.)

msparkles avatar Apr 13 '22 04:04 msparkles