Gun dropping does not apply impulse for some reason FIXED

This commit is contained in:
Franklin 2023-11-26 12:31:50 -04:00
parent f910f4005b
commit 5dd36d5eb2
3 changed files with 22 additions and 11 deletions

View File

@ -101,8 +101,8 @@ pub fn drop_slot_in_game_world(
drop_position.rotate_x(45.0f32.to_radians());
drop_position.rotate_z(45.0f32.to_radians());
let drop_impulse = player_transform.translation
+ (player_transform.up() * 1000000.0)
+ (player_transform.forward() * 3000000.0);
+ (player_transform.up() * 100.0)
+ (player_transform.forward() * 100.0);
let item_inventory_slot = match slot {
PlayerInventorySlotType::Primary => {

View File

@ -2,12 +2,12 @@ use std::sync::Arc;
use bevy::{prelude::*, gltf::Gltf};
use bevy_inspector_egui::egui::mutex::Mutex;
use bevy_rapier3d::{dynamics::{RigidBody, GravityScale, ExternalImpulse}, geometry::ColliderMassProperties};
use bevy_rapier3d::dynamics::{RigidBody, GravityScale, ExternalImpulse, AdditionalMassProperties};
use crate::{comps::core::{
grid::UGrid,
items::item::{Item, ItemType, ItemId},
markers::{holdable::HoldableObjectType, interactable::Interactable, proxy::weapons::initial_attachments::InitialAttachments}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
markers::{holdable::HoldableObjectType, interactable::Interactable, proxy::{weapons::initial_attachments::InitialAttachments, physics::rapier::WhenColliderAddImpulse}}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
#[derive(Component, Clone)]
@ -118,13 +118,13 @@ impl Item for Ak105GunItem {
..Default::default()
},
RigidBody::Dynamic,
ColliderMassProperties::Mass(0.1),
AdditionalMassProperties::Mass(5.0),
GravityScale(4.0),
ExternalImpulse {
impulse: with_impulse,
..Default::default()
},
Interactable::Item(Arc::new(self.clone())),
WhenColliderAddImpulse(ExternalImpulse {
impulse: with_impulse,
torque_impulse: Vec3::ZERO,
}),
self.id(),
))
.push_children(&[firearm_asset_entity]);

View File

@ -1,9 +1,10 @@
use bevy::prelude::*;
use bevy_rapier3d::dynamics::RigidBody as RapierRigidBody;
use bevy_rapier3d::dynamics::{RigidBody as RapierRigidBody, ExternalImpulse};
use bevy_rapier3d::geometry::Collider as RapierCollider;
use bevy_rapier3d::prelude::ComputedColliderShape;
use crate::comps::core::markers::player::Player;
use crate::utils::hierarchy::find_child_in_parent_children;
use super::utils::*;
@ -34,6 +35,10 @@ pub enum AutoAABBCollider {
Capsule,
}
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct WhenColliderAddImpulse(pub ExternalImpulse);
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub struct LinkToPlayer;
@ -42,6 +47,7 @@ pub struct LinkToPlayer;
pub fn physics_replace_proxies(
meshes: Res<Assets<Mesh>>,
mesh_handles: Query<&Handle<Mesh>>,
impulses_to_be_applied: Query<(Entity, &WhenColliderAddImpulse)>,
mut proxy_colliders: Query<
(Entity, &Collider, &Name, &mut Visibility, Option<&LinkToPlayer>, &Parent),
(Without<RapierCollider>, Added<Collider>),
@ -90,7 +96,7 @@ pub fn physics_replace_proxies(
;
}
Collider::Mesh => {
for (_, collider_mesh) in
for (collider_entity, collider_mesh) in
Mesh::search_in_children(entity, &children, &meshes, &mesh_handles)
{
println!("Mesh");
@ -99,6 +105,11 @@ pub fn physics_replace_proxies(
&ComputedColliderShape::ConvexHull,
)
.unwrap();
for (impulse_entity, impulse_to_be_applied) in impulses_to_be_applied.iter() {
if find_child_in_parent_children(&mut commands, impulse_entity, collider_entity, &children) {
commands.entity(impulse_entity).insert(impulse_to_be_applied.0);
}
}
//rapier_collider.set_scale(Vec3 { x: 3.0, y: 3.0, z: 3.0 }, 1);
commands
.entity(entity)