fix impulse of head/key drops

This commit is contained in:
2025-12-09 08:23:59 -05:00
parent 456d6ec92a
commit 5c0e78cb8a
4 changed files with 16 additions and 22 deletions

View File

@@ -12,7 +12,7 @@ use shared::{
player::Player,
protocol::{GltfSceneRoot, PlaySound},
utils::{
billboards::Billboard, one_shot_force::OneShotForce, squish_animation::SquishAnimation,
billboards::Billboard, one_shot_force::OneShotImpulse, squish_animation::SquishAnimation,
},
};
use std::f32::consts::PI;
@@ -28,15 +28,9 @@ fn on_head_drop(
time: Res<Time>,
) -> Result<(), BevyError> {
let drop = trigger.event();
let should_impulse = drop.impulse;
let angle = rand::random::<f32>() * PI * 2.;
let spawn_dir = Quat::from_rotation_y(angle) * Vec3::new(0.5, 0.6, 0.).normalize();
let spawn_force = if should_impulse {
spawn_dir * 180.0 / time.delta_secs()
} else {
Vec3::ZERO
};
let spawn_impulse = Quat::from_rotation_y(angle) * Vec3::new(0.5, 0.6, 0.).normalize() * 180.;
if drop.impulse {
commands.server_trigger(ToClients {
@@ -55,11 +49,8 @@ fn on_head_drop(
Collider::sphere(1.5),
LockedAxes::ROTATION_LOCKED,
RigidBody::Dynamic,
OneShotForce(spawn_force),
CollisionLayers::new(
GameLayer::CollectiblePhysics,
LayerMask::ALL & !GameLayer::Player.to_bits(),
),
OneShotImpulse(spawn_impulse),
CollisionLayers::new(GameLayer::CollectiblePhysics, GameLayer::Level),
Restitution::new(0.6),
Children::spawn(SpawnWith({
let head_id = drop.head_id;