#Rapier2d : Got no CollisionEvent on colliders colliding

10 messages · Page 1 of 1 (latest)

prisma oak
#

I'm trying to build a Top-Down Vampire survivors like, and i'm trying to use Rapier2d for detecting collisions between the mobs and the player.

I have two problems :

  1. My Sensor Colliders still act like Physic Colliders and stop the player when he gets in contact with the small robot

  2. I don't get Collision Events except in very wierd spots, I imagine my colliders are perhaps clipping and thus they would be considered touching ?

#

My code :

Player

 commands.spawn((
        SpriteSheetBundle {
            sprite: TextureAtlasSprite {
                index: 2,
                custom_size: Some(Vec2::new(32.0 * 2.0, 48.0 * 2.0)),
                anchor: Anchor::BottomCenter,
                ..Default::default()
            },
            texture_atlas: texture_atlas_handle,
            ..Default::default()
        },
        Collider::capsule_y(25.0, 10.0),
        Sensor,
        RigidBody::KinematicPositionBased,
        KinematicCharacterController {
            offset: CharacterLength::Absolute(0.0),
            ..default()
        },
        ActiveEvents::COLLISION_EVENTS,
        ActiveCollisionTypes::KINEMATIC_KINEMATIC,
        Player,
        Speed(250.0),
        PlayerAnimation {
            timer: Timer::from_seconds(0.1, TimerMode::Repeating),
            state: PlayerAnimationState::Idle,
        },
        Name::new("Player"),
    ));
}

Robot :

 commands.spawn((
        SpriteBundle {
            texture: asset_server.load("ennemies/ball/ball.png"),
            transform: Transform::from_xyz(-250.0, 0.0, 0.0),
            sprite: Sprite {
                anchor: bevy::sprite::Anchor::BottomCenter,
                custom_size: Some(Vec2::new(64.0, 64.0)),
                ..default()
            },
            ..default()
        },
        Name::from("Ball_1"),
        Collider::ball(10.0),
        Sensor,
        RigidBody::KinematicPositionBased,
        ActiveEvents::COLLISION_EVENTS,
        ActiveCollisionTypes::KINEMATIC_KINEMATIC,
    ));
ornate oyster
#

So when the player approaches the ball from the side, you're getting no event?

prisma oak
#

Yup, only got an event when the tip of the capsule touches the top of the ball collider

prisma oak
#

Got it to work ! Removed the Rigid body on the Player, enabled all collisions on the player with ActiveCollisionTypes::all() and it now behaves how i wanted. Robots are still rigid bodies since i don't want them to clip together and it works like a charm

#

Player :


    commands.spawn((
        SpriteSheetBundle {
            sprite: TextureAtlasSprite {
                index: 2,
                custom_size: Some(Vec2::new(32.0 * 2.0, 48.0 * 2.0)),
                anchor: Anchor::BottomCenter,
                ..Default::default()
            },
            texture_atlas: texture_atlas_handle,
            ..Default::default()
        },
        Collider::capsule_y(25.0, 10.0),
        Sensor,
        ActiveEvents::COLLISION_EVENTS,
        ActiveCollisionTypes::all(),
        Player,
        Speed(250.0),
        PlayerAnimation {
            timer: Timer::from_seconds(0.1, TimerMode::Repeating),
            state: PlayerAnimationState::Idle,
        },
        Name::new("Player"),
    ));```
#

Ennemy :

#
 commands.spawn((
        SpriteBundle {
            texture: asset_server.load("ennemies/ball/ball.png"),
            transform: Transform::from_xyz(-250.0, 0.0, 0.0),
            sprite: Sprite {
                anchor: bevy::sprite::Anchor::BottomCenter,
                custom_size: Some(Vec2::new(64.0, 64.0)),
                ..default()
            },
            ..default()
        },
        Name::from("Ball_1"),
        Collider::ball(10.0),
        Sensor,
        RigidBody::KinematicPositionBased,
    ));