Skip to content

Cuboid Collider Gets Stuck After Contact with Polyline Collider #643

Open
@Mutefish0

Description

@Mutefish0

A cuboid collider attached to a dynamic rigidbody gets stuck after contacting a polyline collider attached to a fixed rigidbody.

As shown in the video: when moving left and right on the square polyline collider, it gets stuck at the corners, but moving on the cuboid collider works fine.

Kapture.2024-06-02.at.17.34.45.mp4

Reproduce

Modify the examples2d/character_controller2.rs file to the following code, then run it.

use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;
use rapier_testbed2d::{KeyCode};


pub fn init_world(testbed: &mut Testbed) {
    /*
     * World
     */
    let mut bodies = RigidBodySet::new();
    let mut colliders = ColliderSet::new();
    let mut impulse_joints = ImpulseJointSet::new();
    let multibody_joints = MultibodyJointSet::new();

    /*
     * Ground
     */
    let ground_size = 10.0;
    let ground_height = 0.1;

    let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height]);
    let floor_handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(ground_size, ground_height);
    colliders.insert_with_parent(collider, floor_handle, &mut bodies);



     /*
     *  Polyline Collider 
     */
    
    let mut points = Vec::new();
    points.push(point![0.0, 0.0]);
    points.push(point![0.0, 2.0]);
    points.push(point![2.0, 2.0]);
    points.push(point![2.0, 0.0]);
    points.push(point![0.0, 0.0]);

    let rigid_body = RigidBodyBuilder::fixed();
    let handle = bodies.insert(rigid_body);
    let collider: ColliderBuilder = ColliderBuilder::polyline(points, None);
    colliders.insert_with_parent(collider, handle, &mut bodies);
     /*
     *  Box Collider 
     */
    let rigid_body = RigidBodyBuilder::fixed().translation(vector![5.0, 1.0]);
    let handle = bodies.insert(rigid_body);
    let collider = ColliderBuilder::cuboid(1.0, 1.0);
    colliders.insert_with_parent(collider, handle, &mut bodies);


    /*
     * Character we will control manually.
     */
    let rb = RigidBodyBuilder::dynamic().lock_rotations().translation(vector![-3.0, 5.0]);
    let character_handle = bodies.insert(rb);
    let collider = ColliderBuilder::cuboid(0.5, 0.5).friction(0.0).restitution(0.0).restitution_combine_rule(CoefficientCombineRule::Multiply).friction_combine_rule(CoefficientCombineRule::Multiply);
    colliders.insert_with_parent(collider, character_handle, &mut bodies);



    /*
     * Set up the testbed.
     */
    testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
    //testbed.set_character_body(character_handle);
    testbed.look_at(point![0.0, 1.0], 100.0);


    testbed.add_callback(move |gfx, physics, _, _| {
        let Some(gfx) = gfx else { return };

    
        for key in gfx.keys().get_pressed() {
            match *key {
                KeyCode::ArrowRight => {
                    let rb = physics.bodies.get_mut(character_handle).unwrap();

                    let vel = rb.linvel();

                    rb.set_linvel(vector![2.0, vel.y], true);
                }
                KeyCode::ArrowLeft => {
                    let rb = physics.bodies.get_mut(character_handle).unwrap();
                    let vel = rb.linvel();
                    rb.set_linvel(vector![-2.0, vel.y], true);
                }

                KeyCode::Space => {
                    let rb = physics.bodies.get_mut(character_handle).unwrap();
                    let vel = rb.linvel();
                    rb.set_linvel(vector![vel.x, 6.0], true);
                }
                
                _ => {}
            }
        }


        for key in gfx.keys().get_just_released() {
            match *key {
                KeyCode::ArrowRight => {
                    let rb = physics.bodies.get_mut(character_handle).unwrap();

                    let vel = rb.linvel();

                    rb.set_linvel(vector![0.0, vel.y], true);
                }
                KeyCode::ArrowLeft => {
                    let rb = physics.bodies.get_mut(character_handle).unwrap();
                    let vel = rb.linvel();
                    rb.set_linvel(vector![0.0, vel.y], true);
                }

               
                
                _ => {}
            }
        }   
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    2DThe issue is specifically about the 2D version of Rapier.C-BugSomething isn't workingD-MediumP-Medium

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions