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

KinematicCharacterControllerOutput not working on KinematicVelocityBased entities #495

Open
AntoineRR opened this issue Apr 22, 2024 · 0 comments
Labels
A-Integration very bevy specific D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Medium S-not-started Work has not started

Comments

@AntoineRR
Copy link

I've been trying to detect collisions using the KinematicCharacterControllerOutput Component for an entity I control through its Velocity (i.e. having a Rigibbody::KinematicVelocityBased Component. However the output component does not seem to be added automatically. When adding it manually, it is not updated when I move the entity. Here is a simple example reproducing the issue with bevy 0.13.1 and bevy_rapier3d 0.25.0 :

use bevy::prelude::*;
use bevy_rapier3d::prelude::*;

#[derive(Component, Default)]
struct MyCube;

fn spawn(mut commands: Commands) {
    commands.spawn((
        RigidBody::Fixed,
        Collider::cuboid(10.0, 1.0, 10.0),
        TransformBundle::default(),
    ));

    commands.spawn((
        RigidBody::KinematicVelocityBased,
        KinematicCharacterController::default(),
        KinematicCharacterControllerOutput::default(),
        TransformBundle {
            local: Transform::from_translation(Vec3::new(0.0, 10.0, 0.0)),
            ..default()
        },
        Velocity {
            linvel: Vec3::new(0.0, -10.0, 0.0),
            ..default()
        },
        Collider::cuboid(1.0, 1.0, 1.0),
        ActiveEvents::all(),
        ActiveCollisionTypes::all(),
        MyCube::default(),
    ));
}

fn handle_collisions(cube_query: Query<&KinematicCharacterControllerOutput, With<MyCube>>) {
    let Ok(output) = cube_query.get_single() else {
        return;
    };
    info!("{:?}", output);
    for collision in &output.collisions {
        info!(
            "Ball collided with floor with normal {:?}",
            collision.toi.details.unwrap().normal1,
        );
    }
}

pub struct TestPlugin;

impl Plugin for TestPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Startup, spawn)
            .add_systems(Update, handle_collisions);
    }
}

When using KinematicPositionBased and this snippet to move the cube everything works as expected :

fn move_cube(time: Res<Time>, mut query: Query<&mut KinematicCharacterController>) {
    for mut controller in query.iter_mut() {
        controller.translation = Some(-Vec3::Y * time.delta_seconds() * 10.0);
    }
}

I would expect the KinematicCharacterControllerOutput component to be added and updated for kinematic objects moved using their velocity too, or maybe I am doing something wrong?

@Vrixyz Vrixyz added D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Medium S-not-started Work has not started A-Integration very bevy specific labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Integration very bevy specific D-Difficult Needs strong technical background, domain knowledge, or impacts are high, needs testing... P-Medium S-not-started Work has not started
Projects
None yet
Development

No branches or pull requests

2 participants