Different damage based on body part

This commit is contained in:
Rendo 2025-12-11 20:54:24 +05:00
commit 1d5065cbbf
8 changed files with 86 additions and 101 deletions

View file

@ -306,7 +306,7 @@ func add_dead(team: int):
func is_server_request() -> bool:
return multiplayer.is_server() or multiplayer.get_remote_sender_id() == 1
func shoot(id:int , damage: int, distance: float) -> void:
func shoot(id:int , limb_damage: int, torso_damage: int,head_damage: int, distance: float,damage_reduction_curve: Curve = null) -> void:
if multiplayer.is_server() == false:
return
@ -328,8 +328,22 @@ func shoot(id:int , damage: int, distance: float) -> void:
var collision = space.intersect_ray(ray)
if collision != {} and collision["collider"] is Player:
collision["collider"].take_damage(damage)
var hit_player: Player = collision["collider"]
var shape_object: CollisionShape3D = hit_player.shape_owner_get_owner(collision["shape"])
var reduction: float = 0
if damage_reduction_curve != null:
var distance_to_hit = (player_camera.global_position - collision["position"]).length()/distance
reduction = damage_reduction_curve.sample(distance_to_hit)
match shape_object.get_groups()[0]:
"Head":
hit_player.take_damage(head_damage*reduction)
"Limb":
hit_player.take_damage(limb_damage*reduction)
_:
hit_player.take_damage(torso_damage*reduction)
func interact(id: int) -> void: