Skip to content

Commit

Permalink
update: add child sensor collider to tower
Browse files Browse the repository at this point in the history
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:
- dimforge/bevy_rapier#172
- TLDR: bevy_rapier might need a rework
  • Loading branch information
quackercrumbs committed May 15, 2022
1 parent 511b7a7 commit d086fba
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
});
}

Expand Down

0 comments on commit d086fba

Please sign in to comment.