From 266783018307aef62b98486e426d0fbd0f7a0e9e Mon Sep 17 00:00:00 2001 From: Squinty Date: Fri, 19 Apr 2024 14:27:04 +0000 Subject: [PATCH] Fix explosion impulses to apply against the rigidbody's center of mass --- components/explosive_damage_component.gd | 3 ++- entities/flag/flag.tscn | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/explosive_damage_component.gd b/components/explosive_damage_component.gd index 5d5184f..eba6ff6 100644 --- a/components/explosive_damage_component.gd +++ b/components/explosive_damage_component.gd @@ -20,7 +20,8 @@ class_name ExplosiveDamageComponent extends Area3D func _physics_process(_delta : float) -> void: for body in get_overlapping_bodies(): if body is RigidBody3D: - var direction : Vector3 = (body.global_position - global_position).normalized() + var center_of_mass_global_position : Vector3 = body.center_of_mass + body.global_position + var direction : Vector3 = ( center_of_mass_global_position - global_position).normalized() body.apply_central_impulse(direction * impulse_force) for area in get_overlapping_areas(): diff --git a/entities/flag/flag.tscn b/entities/flag/flag.tscn index c6ee466..7dfd975 100644 --- a/entities/flag/flag.tscn +++ b/entities/flag/flag.tscn @@ -28,6 +28,8 @@ axis_lock_angular_y = true axis_lock_angular_z = true mass = 40.0 physics_material_override = SubResource("PhysicsMaterial_4ymrw") +center_of_mass_mode = 1 +center_of_mass = Vector3(0, 0.5, 0) continuous_cd = true script = ExtResource("1_y7d3d")