feat: added ragdoll, health, death, and adjusted mortar

This commit is contained in:
DottsGit
2026-06-06 00:01:27 -04:00
parent 8984739334
commit acd495893d
7 changed files with 368 additions and 43 deletions
+9
View File
@@ -202,6 +202,15 @@ func _process(delta: float) -> void:
t_arm_r_rot.x = deg_to_rad(-160)
t_leg_l_rot.x = deg_to_rad(20)
t_leg_r_rot.x = deg_to_rad(20)
"death":
# Fall backwards like a plank
t_root_rot.x = deg_to_rad(-90)
t_root_pos.y = -0.5 # Shift down slightly so it rests on floor
t_arm_l_rot.x = deg_to_rad(170)
t_arm_r_rot.x = deg_to_rad(170)
t_leg_l_rot.x = deg_to_rad(-10)
t_leg_r_rot.x = deg_to_rad(10)
# Smoothly interpolate towards target values
var lerp_speed = 15.0 * delta
+95
View File
@@ -0,0 +1,95 @@
extends Node3D
class_name ProceduralRagdoll
var torso_body: RigidBody3D
func build_ragdoll(color: Color) -> void:
var mat := StandardMaterial3D.new()
mat.albedo_color = color
mat.roughness = 0.8
# Create bodies
torso_body = _create_body(Vector3(0.4, 0.7, 0.25), mat, Vector3(0, 1.15, 0), 20.0)
var head_body = _create_body(Vector3(0.25, 0.25, 0.25), mat, Vector3(0, 1.65, 0), 5.0)
var arm_l_body = _create_body(Vector3(0.12, 0.65, 0.12), mat, Vector3(-0.28, 1.15, 0), 5.0)
var arm_r_body = _create_body(Vector3(0.12, 0.65, 0.12), mat, Vector3(0.28, 1.15, 0), 5.0)
var leg_l_body = _create_body(Vector3(0.15, 0.8, 0.15), mat, Vector3(-0.12, 0.4, 0), 8.0)
var leg_r_body = _create_body(Vector3(0.15, 0.8, 0.15), mat, Vector3(0.12, 0.4, 0), 8.0)
add_child(torso_body)
add_child(head_body)
add_child(arm_l_body)
add_child(arm_r_body)
add_child(leg_l_body)
add_child(leg_r_body)
# Need to wait a frame for paths to be valid before creating joints
call_deferred("_setup_joints", head_body, arm_l_body, arm_r_body, leg_l_body, leg_r_body)
func _setup_joints(head_body, arm_l_body, arm_r_body, leg_l_body, leg_r_body) -> void:
_create_joint(torso_body, head_body, Vector3(0, 1.5, 0))
_create_joint(torso_body, arm_l_body, Vector3(-0.28, 1.45, 0))
_create_joint(torso_body, arm_r_body, Vector3(0.28, 1.45, 0))
_create_joint(torso_body, leg_l_body, Vector3(-0.12, 0.8, 0))
_create_joint(torso_body, leg_r_body, Vector3(0.12, 0.8, 0))
func apply_initial_velocities(linear_vel: Vector3, impulse: Vector3) -> void:
for child in get_children():
if child is RigidBody3D:
child.linear_velocity = linear_vel
# Add random tumbling velocity so they don't fall perfectly still
child.angular_velocity = Vector3(randf_range(-5, 5), randf_range(-5, 5), randf_range(-5, 5))
# Apply the weapon impulse mostly to the torso so it yanks the limbs
if is_instance_valid(torso_body):
torso_body.apply_central_impulse(impulse * 2.0)
func _create_body(size: Vector3, mat: Material, pos: Vector3, mass: float) -> RigidBody3D:
var body = RigidBody3D.new()
body.position = pos
body.mass = mass
# Damping prevents insane spinning and explosion
body.linear_damp = 0.5
body.angular_damp = 2.0
var shape = CollisionShape3D.new()
var box_shape = BoxShape3D.new()
box_shape.size = size
shape.shape = box_shape
body.add_child(shape)
var mesh_inst = MeshInstance3D.new()
var box_mesh = BoxMesh.new()
box_mesh.size = size
box_mesh.material = mat
mesh_inst.mesh = box_mesh
mesh_inst.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_ON
body.add_child(mesh_inst)
return body
func _create_joint(node_a: RigidBody3D, node_b: RigidBody3D, pos: Vector3) -> void:
var joint = Generic6DOFJoint3D.new()
add_child(joint)
joint.position = pos
joint.node_a = node_a.get_path()
joint.node_b = node_b.get_path()
# Free angular axes to allow flopping, lock linear
joint.set_flag_x(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
joint.set_flag_y(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
joint.set_flag_z(Generic6DOFJoint3D.FLAG_ENABLE_LINEAR_LIMIT, true)
# Restrict angular limits so it doesn't bend 360 degrees
joint.set_flag_x(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
joint.set_param_x(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, -PI * 0.4)
joint.set_param_x(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, PI * 0.4)
joint.set_flag_y(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
joint.set_param_y(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, -PI * 0.2)
joint.set_param_y(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, PI * 0.2)
joint.set_flag_z(Generic6DOFJoint3D.FLAG_ENABLE_ANGULAR_LIMIT, true)
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_LOWER_LIMIT, -PI * 0.2)
joint.set_param_z(Generic6DOFJoint3D.PARAM_ANGULAR_UPPER_LIMIT, PI * 0.2)
+1
View File
@@ -0,0 +1 @@
uid://comgwjpn00i7g