From d086fba2b8f923bfaee1b98edc996a866b638f62 Mon Sep 17 00:00:00 2001 From: quackercrumbs Date: Sat, 14 May 2022 19:17:47 -0400 Subject: [PATCH] update: add child sensor collider to tower This sensor will be used to determine the attack range of the tower. NOTE: discovered that the collider doesn't use the global transform to stay in sync. More about this issue can be found here: - https://github.com/dimforge/bevy_rapier/issues/172 - TLDR: bevy_rapier might need a rework --- src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 302f964..25757ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,7 +85,6 @@ fn setup_world( commands .spawn() .insert(Tower) - .insert(Collider::cuboid(cube_size, cube_size, cube_size)) .insert_bundle(PbrBundle { mesh: meshes.add(Mesh::from(bevy::prelude::shape::Box { min_x: -cube_size, @@ -98,6 +97,19 @@ fn setup_world( material: materials.add(Color::rgb(1., 0., 0.).into()), transform: Transform::from_xyz(0.0, cube_size, 0.0), ..Default::default() + }) + .insert(Collider::cuboid(cube_size, cube_size, cube_size)) + .with_children(|parent| { + // sensor range + let sensor_range = cube_size * 10.0; + parent + .spawn() + // NOTE: there is an issue where the Global Transform isn't being used by rapier (https://github.com/dimforge/bevy_rapier/issues/172) + // So that means, if we move the parent transform around, the collider won't get syncd because it's only using the Transform (the child one) + // For now, we'll just hard code it at the origin. If we want to test / make updates, we'll have to update the Transform (the child one) + .insert_bundle((Transform::from_xyz(0.0, sensor_range, 0.0), GlobalTransform::default())) + .insert(Collider::cuboid(sensor_range, sensor_range, sensor_range)) + .insert(Sensor(true)); }); }