Restore transforms so portals' transforms update correctly, and don't add children twice.
This commit is contained in:
parent
e8a15fd84d
commit
ef55419bb7
13
src/map.rs
13
src/map.rs
|
@ -134,6 +134,8 @@ pub struct MapBundle<D: 'static + Clone + Default + Send + Sync> {
|
||||||
pub spawn_colliders: SpawnColliders,
|
pub spawn_colliders: SpawnColliders,
|
||||||
pub spawn_collider_per_tile: SpawnColliderPerTile,
|
pub spawn_collider_per_tile: SpawnColliderPerTile,
|
||||||
pub spawn_portals: SpawnPortals,
|
pub spawn_portals: SpawnPortals,
|
||||||
|
pub transform: Transform,
|
||||||
|
pub global_transform: GlobalTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridBuilder {
|
pub struct GridBuilder {
|
||||||
|
@ -363,9 +365,9 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
map: Query<(Entity, &Map<D>, &SpawnPortals), Changed<SpawnPortals>>,
|
map: Query<(Entity, &Map<D>, &SpawnPortals), Changed<SpawnPortals>>,
|
||||||
) {
|
) {
|
||||||
for (entity, map, spawn_portals) in map.iter() {
|
for (map_entity, map, spawn_portals) in map.iter() {
|
||||||
if **spawn_portals {
|
if **spawn_portals {
|
||||||
commands.entity(entity).remove::<SpawnPortals>();
|
commands.entity(map_entity).remove::<SpawnPortals>();
|
||||||
let mut portals: Vec<(f32, f32)> = vec![];
|
let mut portals: Vec<(f32, f32)> = vec![];
|
||||||
for x in 1..map.width {
|
for x in 1..map.width {
|
||||||
for y in 1..map.height {
|
for y in 1..map.height {
|
||||||
|
@ -407,7 +409,7 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
commands.entity(entity).push_children(&[portal]);
|
commands.entity(map_entity).push_children(&[portal]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,10 +417,10 @@ fn spawn_portals<D: 'static + Clone + Default + Send + Sync>(
|
||||||
|
|
||||||
fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
map: Query<(Entity, &SpawnColliders), With<Map<D>>>,
|
map: Query<&SpawnColliders, With<Map<D>>>,
|
||||||
portals: Query<(Entity, &Transform), (With<Portal>, Without<Collider>)>,
|
portals: Query<(Entity, &Transform), (With<Portal>, Without<Collider>)>,
|
||||||
) {
|
) {
|
||||||
for (map_entity, spawn_colliders) in map.iter() {
|
for spawn_colliders in map.iter() {
|
||||||
if **spawn_colliders {
|
if **spawn_colliders {
|
||||||
for (portal_entity, coordinates) in portals.iter() {
|
for (portal_entity, coordinates) in portals.iter() {
|
||||||
let position = Vec2::new(coordinates.x() + 0.5, coordinates.y() + 0.5);
|
let position = Vec2::new(coordinates.x() + 0.5, coordinates.y() + 0.5);
|
||||||
|
@ -428,7 +430,6 @@ fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
.insert(Collider::cuboid(0.5, 0.5))
|
.insert(Collider::cuboid(0.5, 0.5))
|
||||||
.insert(Sensor(true))
|
.insert(Sensor(true))
|
||||||
.insert(ActiveEvents::COLLISION_EVENTS);
|
.insert(ActiveEvents::COLLISION_EVENTS);
|
||||||
commands.entity(map_entity).push_children(&[portal_entity]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user