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>,
|
||||
resources: Res<BulletResources>,
|
||||
) {
|
||||
for event in events.read()
|
||||
let to_bullet_entity = |event: &BulletFiredEvent|
|
||||
{
|
||||
let rotation = Quat::from_scaled_axis(Vec3::new(
|
||||
rand::random::<f32>() * f32::to_radians(360.0),
|
||||
@ -68,21 +68,24 @@ fn on_bullet_fired_event(
|
||||
));
|
||||
let transform = Transform::IDENTITY
|
||||
.with_translation(event.position)
|
||||
.with_scale(Vec3::splat(event.radius))
|
||||
.with_rotation(rotation)
|
||||
.with_scale(Vec3::splat(event.radius))
|
||||
.looking_to(event.direction, Vec3::Y);
|
||||
|
||||
commands.spawn((
|
||||
(
|
||||
Bullet,
|
||||
resources.mesh.clone(),
|
||||
resources.material.clone(),
|
||||
resources.collider.clone(),
|
||||
transform,
|
||||
ColliderDensity(event.density),
|
||||
AngularVelocity(event.gyro * event.direction),
|
||||
RigidBody::Dynamic,
|
||||
FrameRaycastAntiGhost,
|
||||
ColliderDensity(event.density),
|
||||
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