Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb5708e19e | ||
|
|
6aae02bef8 | ||
|
|
acd495893d |
@@ -202,6 +202,15 @@ func _process(delta: float) -> void:
|
|||||||
t_arm_r_rot.x = deg_to_rad(-160)
|
t_arm_r_rot.x = deg_to_rad(-160)
|
||||||
t_leg_l_rot.x = deg_to_rad(20)
|
t_leg_l_rot.x = deg_to_rad(20)
|
||||||
t_leg_r_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
|
# Smoothly interpolate towards target values
|
||||||
var lerp_speed = 15.0 * delta
|
var lerp_speed = 15.0 * delta
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://comgwjpn00i7g
|
||||||
@@ -222,6 +222,11 @@ func _build_target_dummy() -> void:
|
|||||||
dummy.position = Vector3(0, 0, -10)
|
dummy.position = Vector3(0, 0, -10)
|
||||||
add_child(dummy)
|
add_child(dummy)
|
||||||
|
|
||||||
|
var killable = load("res://entities/killable_dummy.gd").new()
|
||||||
|
killable.name = "KillableDummy"
|
||||||
|
killable.position = Vector3(5, 0, -10)
|
||||||
|
add_child(killable)
|
||||||
|
|
||||||
# ── Lighting ──────────────────────────────────────────────────────────────────
|
# ── Lighting ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
func _build_lighting() -> void:
|
func _build_lighting() -> void:
|
||||||
@@ -432,44 +437,6 @@ func _build_hud() -> void:
|
|||||||
_chain_label.add_theme_color_override("font_color", Color(1.0, 0.8, 0.3))
|
_chain_label.add_theme_color_override("font_color", Color(1.0, 0.8, 0.3))
|
||||||
vbox.add_child(_chain_label)
|
vbox.add_child(_chain_label)
|
||||||
|
|
||||||
# ── Help text ─────────────────────────────────────────────────────────
|
|
||||||
var help_panel := PanelContainer.new()
|
|
||||||
help_panel.name = "HelpPanel"
|
|
||||||
help_panel.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
|
|
||||||
help_panel.offset_left = 12
|
|
||||||
help_panel.offset_top = -90
|
|
||||||
help_panel.offset_right = 620
|
|
||||||
help_panel.offset_bottom = -12
|
|
||||||
var help_style := StyleBoxFlat.new()
|
|
||||||
help_style.bg_color = Color(0, 0, 0, 0.4)
|
|
||||||
help_style.corner_radius_top_left = 6
|
|
||||||
help_style.corner_radius_top_right = 6
|
|
||||||
help_style.corner_radius_bottom_left = 6
|
|
||||||
help_style.corner_radius_bottom_right = 6
|
|
||||||
help_style.content_margin_left = 10
|
|
||||||
help_style.content_margin_top = 6
|
|
||||||
help_style.content_margin_right = 10
|
|
||||||
help_style.content_margin_bottom = 6
|
|
||||||
help_panel.add_theme_stylebox_override("panel", help_style)
|
|
||||||
canvas.add_child(help_panel)
|
|
||||||
|
|
||||||
var help := Label.new()
|
|
||||||
help.name = "HelpLabel"
|
|
||||||
|
|
||||||
var k_f = _get_key_name("move_forward")
|
|
||||||
var k_l = _get_key_name("move_left")
|
|
||||||
var k_b = _get_key_name("move_back")
|
|
||||||
var k_r = _get_key_name("move_right")
|
|
||||||
var k_j = _get_key_name("jump")
|
|
||||||
var k_c = _get_key_name("crouch")
|
|
||||||
var k_d = _get_key_name("dash")
|
|
||||||
var k_fire = _get_key_name("fire")
|
|
||||||
|
|
||||||
var help_text = "%s%s%s%s Move | %s Jump | %s (in air) Double Jump\n%s (moving fast) Slide | %s Dash | %s Fire | ESC Pause Menu" % [k_f, k_l, k_b, k_r, k_j, k_j, k_c, k_d, k_fire]
|
|
||||||
help.text = help_text
|
|
||||||
help.add_theme_font_size_override("font_size", 13)
|
|
||||||
help.add_theme_color_override("font_color", Color(0.8, 0.8, 0.8, 0.7))
|
|
||||||
help_panel.add_child(help)
|
|
||||||
|
|
||||||
# ── Weapon & Ammo Panel ───────────────────────────────────────────────
|
# ── Weapon & Ammo Panel ───────────────────────────────────────────────
|
||||||
var wp_panel := PanelContainer.new()
|
var wp_panel := PanelContainer.new()
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
extends StaticBody3D
|
||||||
|
class_name KillableDummy
|
||||||
|
|
||||||
|
var visual_node: Node3D
|
||||||
|
var col_shape: CollisionShape3D
|
||||||
|
var label: Label3D
|
||||||
|
|
||||||
|
var max_health: float = 100.0
|
||||||
|
var health: float = 100.0
|
||||||
|
var max_shield: float = 100.0
|
||||||
|
var shield: float = 100.0
|
||||||
|
|
||||||
|
var is_dead: bool = false
|
||||||
|
var ragdoll_instance: Node3D = null
|
||||||
|
var pending_impulse: Vector3 = Vector3.ZERO
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
add_to_group("enemies")
|
||||||
|
|
||||||
|
col_shape = CollisionShape3D.new()
|
||||||
|
col_shape.shape = CapsuleShape3D.new()
|
||||||
|
col_shape.shape.radius = 0.5
|
||||||
|
col_shape.shape.height = 2.0
|
||||||
|
col_shape.position = Vector3(0, 1.0, 0)
|
||||||
|
add_child(col_shape)
|
||||||
|
|
||||||
|
visual_node = load("res://characters/humanoid_model.gd").new()
|
||||||
|
visual_node.name = "HumanoidModel"
|
||||||
|
visual_node.color = Color(0.8, 0.5, 0.1) # Orange for killable
|
||||||
|
add_child(visual_node)
|
||||||
|
|
||||||
|
label = Label3D.new()
|
||||||
|
label.pixel_size = 0.01
|
||||||
|
label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||||
|
label.position = Vector3(0, 2.3, 0)
|
||||||
|
label.modulate = Color(1, 1, 1)
|
||||||
|
add_child(label)
|
||||||
|
|
||||||
|
_update_label()
|
||||||
|
|
||||||
|
func take_damage(amount: float, hit_position: Vector3, source: Node = null) -> void:
|
||||||
|
if is_dead:
|
||||||
|
return
|
||||||
|
|
||||||
|
var dmg_taken = amount
|
||||||
|
if shield > 0:
|
||||||
|
if shield >= amount:
|
||||||
|
shield -= amount
|
||||||
|
amount = 0
|
||||||
|
else:
|
||||||
|
amount -= shield
|
||||||
|
shield = 0
|
||||||
|
|
||||||
|
if amount > 0:
|
||||||
|
health -= amount
|
||||||
|
|
||||||
|
_update_label()
|
||||||
|
|
||||||
|
if source and source.has_method("spawn_damage_number"):
|
||||||
|
source.spawn_damage_number(dmg_taken, hit_position)
|
||||||
|
|
||||||
|
if health <= 0:
|
||||||
|
_die(hit_position, source, dmg_taken)
|
||||||
|
else:
|
||||||
|
_wiggle()
|
||||||
|
|
||||||
|
func _update_label() -> void:
|
||||||
|
label.text = "HP: %.0f / SH: %.0f" % [health, shield]
|
||||||
|
|
||||||
|
func apply_impulse(impulse: Vector3) -> void:
|
||||||
|
pending_impulse += impulse
|
||||||
|
|
||||||
|
func _die(_hit_position: Vector3, source: Node, damage_amount: float) -> void:
|
||||||
|
is_dead = true
|
||||||
|
visual_node.visible = false
|
||||||
|
col_shape.set_deferred("disabled", true)
|
||||||
|
label.visible = false
|
||||||
|
|
||||||
|
# Spawn ragdoll
|
||||||
|
var ragdoll_script = preload("res://characters/procedural_ragdoll.gd")
|
||||||
|
if ragdoll_script:
|
||||||
|
ragdoll_instance = ragdoll_script.new()
|
||||||
|
get_tree().current_scene.add_child(ragdoll_instance)
|
||||||
|
ragdoll_instance.global_position = global_position
|
||||||
|
ragdoll_instance.build_ragdoll(Color(0.8, 0.5, 0.1))
|
||||||
|
|
||||||
|
# Calculate impulse
|
||||||
|
var linear_vel = Vector3.ZERO
|
||||||
|
var impulse = Vector3.ZERO
|
||||||
|
|
||||||
|
if pending_impulse.length_squared() > 0.01:
|
||||||
|
# The player treats incoming impulses as direct velocity additions (v += impulse)
|
||||||
|
# To make the dummy fly exactly like the player, we must use it as base linear velocity!
|
||||||
|
linear_vel = pending_impulse
|
||||||
|
impulse = pending_impulse * 0.5
|
||||||
|
pending_impulse = Vector3.ZERO
|
||||||
|
else:
|
||||||
|
var hit_dir = Vector3.BACK
|
||||||
|
|
||||||
|
# Try to get direction from the player's camera
|
||||||
|
if source and source is CharacterBody3D:
|
||||||
|
var cam = source.get_node_or_null("HeadPivot/Camera3D")
|
||||||
|
if cam:
|
||||||
|
hit_dir = (_hit_position - cam.global_position).normalized()
|
||||||
|
|
||||||
|
linear_vel = hit_dir * (damage_amount * 0.05)
|
||||||
|
impulse = hit_dir * (damage_amount * 1.5)
|
||||||
|
|
||||||
|
get_tree().create_timer(0.01).timeout.connect(func():
|
||||||
|
if is_instance_valid(ragdoll_instance):
|
||||||
|
ragdoll_instance.apply_initial_velocities(linear_vel, impulse)
|
||||||
|
)
|
||||||
|
|
||||||
|
get_tree().create_timer(3.0).timeout.connect(func():
|
||||||
|
_respawn()
|
||||||
|
)
|
||||||
|
|
||||||
|
func _respawn() -> void:
|
||||||
|
if is_instance_valid(ragdoll_instance):
|
||||||
|
ragdoll_instance.queue_free()
|
||||||
|
|
||||||
|
health = max_health
|
||||||
|
shield = max_shield
|
||||||
|
is_dead = false
|
||||||
|
|
||||||
|
visual_node.visible = true
|
||||||
|
col_shape.set_deferred("disabled", false)
|
||||||
|
label.visible = true
|
||||||
|
_update_label()
|
||||||
|
|
||||||
|
func _wiggle() -> void:
|
||||||
|
var tween = create_tween()
|
||||||
|
var orig_pos = Vector3.ZERO
|
||||||
|
var wiggle_dir = Vector3(randf_range(-0.1, 0.1), 0, randf_range(-0.1, 0.1))
|
||||||
|
|
||||||
|
tween.tween_property(visual_node, "position", orig_pos + wiggle_dir, 0.05)
|
||||||
|
tween.tween_property(visual_node, "position", orig_pos - wiggle_dir, 0.05)
|
||||||
|
tween.tween_property(visual_node, "position", orig_pos, 0.05)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://3d2ftchff0t4
|
||||||
@@ -10,6 +10,23 @@ var head_pivot: Node3D = null # FPSCameraRig node
|
|||||||
var camera: Camera3D = null
|
var camera: Camera3D = null
|
||||||
var _damage_layer: CanvasLayer = null
|
var _damage_layer: CanvasLayer = null
|
||||||
|
|
||||||
|
# Health and Shield
|
||||||
|
var max_health: float = 100.0
|
||||||
|
var health: float = 100.0
|
||||||
|
var max_shield: float = 100.0
|
||||||
|
var shield: float = 100.0
|
||||||
|
var time_since_last_damage: float = 0.0
|
||||||
|
var is_dead: bool = false
|
||||||
|
|
||||||
|
# UI
|
||||||
|
var health_bar: ProgressBar
|
||||||
|
var shield_bar: ProgressBar
|
||||||
|
var health_label: Label
|
||||||
|
var shield_label: Label
|
||||||
|
var death_screen: Control
|
||||||
|
|
||||||
|
var ragdoll_instance: Node3D
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
var footstep_player: AudioStreamPlayer
|
var footstep_player: AudioStreamPlayer
|
||||||
var dash_player: AudioStreamPlayer
|
var dash_player: AudioStreamPlayer
|
||||||
@@ -50,6 +67,7 @@ func _ready() -> void:
|
|||||||
_setup_audio()
|
_setup_audio()
|
||||||
_setup_hit_marker()
|
_setup_hit_marker()
|
||||||
_setup_grapple()
|
_setup_grapple()
|
||||||
|
_setup_hud()
|
||||||
|
|
||||||
set_process(true)
|
set_process(true)
|
||||||
set_physics_process(true)
|
set_physics_process(true)
|
||||||
@@ -188,9 +206,30 @@ func apply_impulse(force: Vector3) -> void:
|
|||||||
# Tiny upward bump helps move_and_slide detach from the floor
|
# Tiny upward bump helps move_and_slide detach from the floor
|
||||||
global_position.y += 0.1
|
global_position.y += 0.1
|
||||||
|
|
||||||
func take_damage(amount: float, _hit_pos: Vector3, _source: Node3D = null) -> void:
|
func take_damage(amount: float, _hit_pos: Vector3, _source: Node3D = null, impulse: Vector3 = Vector3.ZERO) -> void:
|
||||||
|
if is_dead:
|
||||||
|
if is_instance_valid(ragdoll_instance):
|
||||||
|
ragdoll_instance.apply_initial_velocities(Vector3.ZERO, impulse)
|
||||||
|
return
|
||||||
|
|
||||||
# Show damage number for self-damage
|
# Show damage number for self-damage
|
||||||
spawn_damage_number(amount, _hit_pos)
|
spawn_damage_number(amount, _hit_pos)
|
||||||
|
|
||||||
|
time_since_last_damage = 0.0
|
||||||
|
|
||||||
|
if shield > 0.0:
|
||||||
|
if shield >= amount:
|
||||||
|
shield -= amount
|
||||||
|
amount = 0.0
|
||||||
|
else:
|
||||||
|
amount -= shield
|
||||||
|
shield = 0.0
|
||||||
|
|
||||||
|
if amount > 0.0:
|
||||||
|
health -= amount
|
||||||
|
if health <= 0.0:
|
||||||
|
health = 0.0
|
||||||
|
die(impulse)
|
||||||
|
|
||||||
func _ensure_machine() -> MovementStateMachine:
|
func _ensure_machine() -> MovementStateMachine:
|
||||||
if is_instance_valid(_machine):
|
if is_instance_valid(_machine):
|
||||||
@@ -292,3 +331,221 @@ func _on_movement_event(ev: String, data: Dictionary) -> void:
|
|||||||
grapple_shoot_player.play()
|
grapple_shoot_player.play()
|
||||||
elif ev == "grapple_latch":
|
elif ev == "grapple_latch":
|
||||||
grapple_latch_player.play()
|
grapple_latch_player.play()
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if is_dead:
|
||||||
|
# Continuously follow the ragdoll torso
|
||||||
|
if is_instance_valid(ragdoll_instance) and is_instance_valid(camera):
|
||||||
|
var torso = ragdoll_instance.torso_body
|
||||||
|
if is_instance_valid(torso) and ragdoll_instance.has_meta("spring_arm"):
|
||||||
|
var spring_arm = ragdoll_instance.get_meta("spring_arm")
|
||||||
|
if is_instance_valid(spring_arm):
|
||||||
|
# Follow torso position exactly to avoid lerp bobbing
|
||||||
|
spring_arm.global_position = torso.global_position
|
||||||
|
return
|
||||||
|
|
||||||
|
# Shield recharge logic
|
||||||
|
time_since_last_damage += delta
|
||||||
|
if time_since_last_damage >= 5.0 and shield < max_shield:
|
||||||
|
shield += 20.0 * delta
|
||||||
|
if shield > max_shield:
|
||||||
|
shield = max_shield
|
||||||
|
|
||||||
|
# Update UI
|
||||||
|
if is_instance_valid(health_bar):
|
||||||
|
health_bar.value = health
|
||||||
|
health_label.text = "%d / %d" % [ceil(health), max_health]
|
||||||
|
if is_instance_valid(shield_bar):
|
||||||
|
shield_bar.value = shield
|
||||||
|
shield_label.text = "%d / %d" % [ceil(shield), max_shield]
|
||||||
|
|
||||||
|
func _setup_hud() -> void:
|
||||||
|
var margin = MarginContainer.new()
|
||||||
|
margin.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
|
||||||
|
margin.offset_left = 20
|
||||||
|
margin.offset_bottom = -20
|
||||||
|
margin.grow_vertical = Control.GROW_DIRECTION_BEGIN
|
||||||
|
|
||||||
|
var vbox = VBoxContainer.new()
|
||||||
|
margin.add_child(vbox)
|
||||||
|
|
||||||
|
# Shield Bar (Top)
|
||||||
|
var shield_box = VBoxContainer.new()
|
||||||
|
var s_title = Label.new()
|
||||||
|
s_title.text = "SHIELD"
|
||||||
|
s_title.add_theme_font_size_override("font_size", 12)
|
||||||
|
s_title.add_theme_color_override("font_color", Color(0.4, 0.7, 1.0))
|
||||||
|
shield_box.add_child(s_title)
|
||||||
|
|
||||||
|
shield_bar = ProgressBar.new()
|
||||||
|
shield_bar.custom_minimum_size = Vector2(200, 20)
|
||||||
|
shield_bar.max_value = max_shield
|
||||||
|
shield_bar.value = shield
|
||||||
|
shield_bar.show_percentage = false
|
||||||
|
|
||||||
|
var s_sb = StyleBoxFlat.new()
|
||||||
|
s_sb.bg_color = Color(0.1, 0.4, 0.8)
|
||||||
|
shield_bar.add_theme_stylebox_override("fill", s_sb)
|
||||||
|
|
||||||
|
shield_label = Label.new()
|
||||||
|
shield_label.text = "100 / 100"
|
||||||
|
shield_label.set_anchors_preset(Control.PRESET_CENTER)
|
||||||
|
shield_bar.add_child(shield_label)
|
||||||
|
|
||||||
|
shield_box.add_child(shield_bar)
|
||||||
|
vbox.add_child(shield_box)
|
||||||
|
|
||||||
|
# Spacer
|
||||||
|
vbox.add_child(Control.new())
|
||||||
|
|
||||||
|
# Health Bar (Bottom)
|
||||||
|
var health_box = VBoxContainer.new()
|
||||||
|
var h_title = Label.new()
|
||||||
|
h_title.text = "HEALTH"
|
||||||
|
h_title.add_theme_font_size_override("font_size", 12)
|
||||||
|
h_title.add_theme_color_override("font_color", Color(1.0, 0.3, 0.3))
|
||||||
|
health_box.add_child(h_title)
|
||||||
|
|
||||||
|
health_bar = ProgressBar.new()
|
||||||
|
health_bar.custom_minimum_size = Vector2(200, 20)
|
||||||
|
health_bar.max_value = max_health
|
||||||
|
health_bar.value = health
|
||||||
|
health_bar.show_percentage = false
|
||||||
|
|
||||||
|
var h_sb = StyleBoxFlat.new()
|
||||||
|
h_sb.bg_color = Color(0.8, 0.1, 0.1)
|
||||||
|
health_bar.add_theme_stylebox_override("fill", h_sb)
|
||||||
|
|
||||||
|
health_label = Label.new()
|
||||||
|
health_label.text = "100 / 100"
|
||||||
|
health_label.set_anchors_preset(Control.PRESET_CENTER)
|
||||||
|
health_bar.add_child(health_label)
|
||||||
|
|
||||||
|
health_box.add_child(health_bar)
|
||||||
|
vbox.add_child(health_box)
|
||||||
|
|
||||||
|
_damage_layer.add_child(margin)
|
||||||
|
|
||||||
|
# Setup Death Screen
|
||||||
|
death_screen = ColorRect.new()
|
||||||
|
death_screen.color = Color(0, 0, 0, 0.7)
|
||||||
|
death_screen.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
|
death_screen.visible = false
|
||||||
|
|
||||||
|
var center = CenterContainer.new()
|
||||||
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
|
death_screen.add_child(center)
|
||||||
|
|
||||||
|
var d_vbox = VBoxContainer.new()
|
||||||
|
d_vbox.add_theme_constant_override("separation", 20)
|
||||||
|
center.add_child(d_vbox)
|
||||||
|
|
||||||
|
var d_title = Label.new()
|
||||||
|
d_title.text = "SYSTEM FAILURE"
|
||||||
|
d_title.add_theme_font_size_override("font_size", 48)
|
||||||
|
d_title.add_theme_color_override("font_color", Color(1.0, 0.2, 0.2))
|
||||||
|
d_vbox.add_child(d_title)
|
||||||
|
|
||||||
|
var respawn_btn = Button.new()
|
||||||
|
respawn_btn.text = "REBOOT"
|
||||||
|
respawn_btn.add_theme_font_size_override("font_size", 24)
|
||||||
|
respawn_btn.pressed.connect(_on_respawn_pressed)
|
||||||
|
d_vbox.add_child(respawn_btn)
|
||||||
|
|
||||||
|
_damage_layer.add_child(death_screen)
|
||||||
|
|
||||||
|
func die(impulse: Vector3 = Vector3.ZERO) -> void:
|
||||||
|
if is_dead: return
|
||||||
|
is_dead = true
|
||||||
|
|
||||||
|
# Disable movement state machine inputs
|
||||||
|
if _machine:
|
||||||
|
_machine.process_mode = Node.PROCESS_MODE_DISABLED
|
||||||
|
|
||||||
|
# Hide old animated model
|
||||||
|
var humanoid = get_node_or_null("HumanoidModel")
|
||||||
|
if humanoid:
|
||||||
|
humanoid.visible = false
|
||||||
|
|
||||||
|
# Disable collision so player doesn't block bullets
|
||||||
|
var col = get_node_or_null("CollisionShape3D")
|
||||||
|
if col:
|
||||||
|
col.set_deferred("disabled", true)
|
||||||
|
|
||||||
|
# Spawn true physics ragdoll
|
||||||
|
var ragdoll = load("res://characters/procedural_ragdoll.gd").new()
|
||||||
|
ragdoll_instance = ragdoll
|
||||||
|
get_tree().current_scene.add_child(ragdoll)
|
||||||
|
ragdoll.global_transform = global_transform
|
||||||
|
ragdoll.build_ragdoll(Color(0.2, 0.4, 0.8)) # Blueish player color
|
||||||
|
|
||||||
|
# Wait a frame for physics to initialize then apply velocity
|
||||||
|
get_tree().create_timer(0.01).timeout.connect(func():
|
||||||
|
if is_instance_valid(ragdoll):
|
||||||
|
ragdoll.apply_initial_velocities(velocity, impulse)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Move camera to 3rd person view using SpringArm3D
|
||||||
|
if is_instance_valid(camera):
|
||||||
|
# Hide the weapon manager so it isn't floating in front of the 3rd person camera
|
||||||
|
var wman = camera.get_node_or_null("WeaponManager")
|
||||||
|
if wman:
|
||||||
|
wman.visible = false
|
||||||
|
|
||||||
|
var cam_trans = camera.global_transform
|
||||||
|
camera.get_parent().remove_child(camera)
|
||||||
|
|
||||||
|
# Determine fixed offset direction for camera to follow from
|
||||||
|
var back_dir = cam_trans.basis.z.normalized()
|
||||||
|
back_dir.y = 0 # Flatten it
|
||||||
|
if back_dir.length_squared() < 0.1:
|
||||||
|
back_dir = Vector3.BACK
|
||||||
|
else:
|
||||||
|
back_dir = back_dir.normalized()
|
||||||
|
|
||||||
|
var spring_arm = SpringArm3D.new()
|
||||||
|
spring_arm.name = "DeathSpringArm"
|
||||||
|
spring_arm.spring_length = 1.5
|
||||||
|
spring_arm.margin = 0.5
|
||||||
|
|
||||||
|
# Give it collision capability against the world but ignore the ragdoll shapes
|
||||||
|
spring_arm.collision_mask = 1 # Environment mask
|
||||||
|
for child in ragdoll.get_children():
|
||||||
|
if child is CollisionObject3D:
|
||||||
|
spring_arm.add_excluded_object(child.get_rid())
|
||||||
|
|
||||||
|
get_tree().current_scene.add_child(spring_arm)
|
||||||
|
|
||||||
|
# Put the arm at the torso's current position
|
||||||
|
spring_arm.global_position = ragdoll.torso_body.global_position
|
||||||
|
|
||||||
|
# Calculate upper-right position
|
||||||
|
var right_dir = back_dir.cross(Vector3.UP).normalized()
|
||||||
|
if right_dir.length_squared() < 0.1:
|
||||||
|
right_dir = Vector3.RIGHT
|
||||||
|
|
||||||
|
# The vector only defines direction, length is controlled by spring_length
|
||||||
|
var desired_cam_pos = spring_arm.global_position + back_dir * 2.5 + right_dir * 1.5 + Vector3.UP * 1.5
|
||||||
|
|
||||||
|
# SpringArm3D extends along its local +Z axis.
|
||||||
|
# look_at() points the local -Z axis at the target.
|
||||||
|
# To point +Z at desired_cam_pos, we must look_at the OPPOSITE direction.
|
||||||
|
var opposite_dir = spring_arm.global_position + (spring_arm.global_position - desired_cam_pos)
|
||||||
|
spring_arm.look_at(opposite_dir, Vector3.UP)
|
||||||
|
|
||||||
|
spring_arm.add_child(camera)
|
||||||
|
|
||||||
|
# Since +Z points outwards to the camera, -Z points inwards to the torso.
|
||||||
|
# Camera3D natively looks down -Z. Setting rotation to ZERO makes it perfectly look at the torso!
|
||||||
|
camera.position = Vector3.ZERO
|
||||||
|
camera.rotation = Vector3.ZERO
|
||||||
|
|
||||||
|
ragdoll_instance.set_meta("spring_arm", spring_arm)
|
||||||
|
|
||||||
|
# Show death screen
|
||||||
|
death_screen.visible = true
|
||||||
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||||
|
|
||||||
|
func _on_respawn_pressed() -> void:
|
||||||
|
# Reload scene
|
||||||
|
get_tree().reload_current_scene()
|
||||||
|
|||||||
@@ -193,6 +193,9 @@ func _shoot_hitscan() -> void:
|
|||||||
var falloff_factor = clampf((hit_dist - falloff_start) / (max_range - falloff_start), 0.0, 1.0)
|
var falloff_factor = clampf((hit_dist - falloff_start) / (max_range - falloff_start), 0.0, 1.0)
|
||||||
damage = lerpf(base_dmg, min_dmg, falloff_factor)
|
damage = lerpf(base_dmg, min_dmg, falloff_factor)
|
||||||
|
|
||||||
|
if result.collider.has_method("apply_impulse"):
|
||||||
|
result.collider.apply_impulse(pellet_dir * 8.0) # Apply strong physical force for ragdoll
|
||||||
|
|
||||||
if result.collider.has_method("take_damage"):
|
if result.collider.has_method("take_damage"):
|
||||||
result.collider.take_damage(damage, result.position, player)
|
result.collider.take_damage(damage, result.position, player)
|
||||||
else:
|
else:
|
||||||
|
|||||||
+3
-3
@@ -6,8 +6,8 @@ func _init() -> void:
|
|||||||
fire_rate = 1.5 # Slow
|
fire_rate = 1.5 # Slow
|
||||||
max_ammo = 1
|
max_ammo = 1
|
||||||
reload_time = 3.0 # Extremely long
|
reload_time = 3.0 # Extremely long
|
||||||
base_damage = 200.0 # Huge damage
|
base_damage = 230.0 # Huge damage
|
||||||
min_damage = 20.0
|
min_damage = 50.0
|
||||||
falloff_start = 0.0
|
falloff_start = 0.0
|
||||||
max_range = 500.0
|
max_range = 500.0
|
||||||
automatic = false
|
automatic = false
|
||||||
@@ -72,7 +72,7 @@ func _spawn_custom_projectile(origin: Vector3, fire_dir: Vector3) -> void:
|
|||||||
# Mortar Bouncing logic
|
# Mortar Bouncing logic
|
||||||
proj.fuse_time = -1.0 # Don't start ticking until it bounces
|
proj.fuse_time = -1.0 # Don't start ticking until it bounces
|
||||||
proj.bounce_fuse_delay = 3.0 # Explodes 3 seconds after first bounce
|
proj.bounce_fuse_delay = 3.0 # Explodes 3 seconds after first bounce
|
||||||
proj.impact_detonate_time = 2.0 # If flying > 2s, explode on impact instead
|
proj.impact_detonate_time = 1.0 # If flying > 1s, explode on impact instead
|
||||||
proj.bounciness = 0.4 # Heavy, loses momentum on bounce
|
proj.bounciness = 0.4 # Heavy, loses momentum on bounce
|
||||||
|
|
||||||
# Explosive stats
|
# Explosive stats
|
||||||
|
|||||||
Reference in New Issue
Block a user