fix impulse of head/key drops
This commit is contained in:
@@ -48,6 +48,10 @@ pub struct HeadCollected {
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.register_type::<HeadDrop>();
|
||||
app.register_type::<HeadDropEnableTime>();
|
||||
app.register_type::<SecretHeadMarker>();
|
||||
|
||||
app.add_systems(
|
||||
Update,
|
||||
enable_collectible.run_if(in_state(GameState::Playing)),
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
player::Player,
|
||||
protocol::{GltfSceneRoot, PlaySound},
|
||||
squish_animation::SquishAnimation,
|
||||
utils::one_shot_force::OneShotForce,
|
||||
utils::one_shot_force::OneShotImpulse,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
@@ -26,14 +26,13 @@ pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, on_spawn_key);
|
||||
}
|
||||
|
||||
fn on_spawn_key(trigger: On<KeySpawn>, mut commands: Commands, time: Res<Time<Fixed>>) {
|
||||
fn on_spawn_key(trigger: On<KeySpawn>, mut commands: Commands) {
|
||||
let KeySpawn(position, id) = trigger.event();
|
||||
|
||||
let id = id.clone();
|
||||
|
||||
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 = spawn_dir * 180.0 / time.delta_secs();
|
||||
let spawn_force = Quat::from_rotation_y(angle) * Vec3::new(0.5, 0.6, 0.).normalize() * 180.;
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
@@ -44,7 +43,7 @@ fn on_spawn_key(trigger: On<KeySpawn>, mut commands: Commands, time: Res<Time<Fi
|
||||
Collider::sphere(1.5),
|
||||
LockedAxes::ROTATION_LOCKED,
|
||||
RigidBody::Dynamic,
|
||||
OneShotForce(spawn_force),
|
||||
OneShotImpulse(spawn_force),
|
||||
CollisionLayers::new(GameLayer::CollectiblePhysics, GameLayer::Level),
|
||||
Restitution::new(0.6),
|
||||
Replicated,
|
||||
|
||||
@@ -6,14 +6,14 @@ pub fn plugin(app: &mut App) {
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct OneShotForce(pub Vec3);
|
||||
pub struct OneShotImpulse(pub Vec3);
|
||||
|
||||
pub fn apply_one_shot_forces(
|
||||
mut commands: Commands,
|
||||
mut query: Query<(Entity, &OneShotForce, Forces)>,
|
||||
mut query: Query<(Entity, &OneShotImpulse, Forces)>,
|
||||
) {
|
||||
for (entity, force, mut forces) in query.iter_mut() {
|
||||
forces.apply_force(force.0);
|
||||
commands.entity(entity).remove::<OneShotForce>();
|
||||
forces.apply_linear_impulse(force.0);
|
||||
commands.entity(entity).remove::<OneShotImpulse>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user