fix: batch spawned projectiles
This commit is contained in:
parent
52c9050d54
commit
eb95345745
@ -59,7 +59,7 @@ fn on_bullet_fired_event(
|
|||||||
mut events: EventReader<BulletFiredEvent>,
|
mut events: EventReader<BulletFiredEvent>,
|
||||||
resources: Res<BulletResources>,
|
resources: Res<BulletResources>,
|
||||||
) {
|
) {
|
||||||
for event in events.read()
|
let to_bullet_entity = |event: &BulletFiredEvent|
|
||||||
{
|
{
|
||||||
let rotation = Quat::from_scaled_axis(Vec3::new(
|
let rotation = Quat::from_scaled_axis(Vec3::new(
|
||||||
rand::random::<f32>() * f32::to_radians(360.0),
|
rand::random::<f32>() * f32::to_radians(360.0),
|
||||||
@ -68,21 +68,24 @@ fn on_bullet_fired_event(
|
|||||||
));
|
));
|
||||||
let transform = Transform::IDENTITY
|
let transform = Transform::IDENTITY
|
||||||
.with_translation(event.position)
|
.with_translation(event.position)
|
||||||
.with_scale(Vec3::splat(event.radius))
|
|
||||||
.with_rotation(rotation)
|
.with_rotation(rotation)
|
||||||
|
.with_scale(Vec3::splat(event.radius))
|
||||||
.looking_to(event.direction, Vec3::Y);
|
.looking_to(event.direction, Vec3::Y);
|
||||||
|
|
||||||
commands.spawn((
|
(
|
||||||
Bullet,
|
Bullet,
|
||||||
resources.mesh.clone(),
|
resources.mesh.clone(),
|
||||||
resources.material.clone(),
|
resources.material.clone(),
|
||||||
resources.collider.clone(),
|
resources.collider.clone(),
|
||||||
transform,
|
transform,
|
||||||
ColliderDensity(event.density),
|
|
||||||
AngularVelocity(event.gyro * event.direction),
|
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
FrameRaycastAntiGhost,
|
ColliderDensity(event.density),
|
||||||
LinearVelocity(event.velocity * event.direction),
|
LinearVelocity(event.velocity * event.direction),
|
||||||
));
|
AngularVelocity(event.gyro * event.direction),
|
||||||
}
|
FrameRaycastAntiGhost,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let bullet_entities = events.read().map(to_bullet_entity).collect::<Vec<_>>();
|
||||||
|
commands.spawn_batch(bullet_entities);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user