damage slow down

This commit is contained in:
Rendo 2025-12-11 22:07:53 +05:00
commit 96f92757b5
9 changed files with 47 additions and 18 deletions

View file

@ -8748,6 +8748,7 @@ script = ExtResource("28_xqgvn")
player = NodePath("..")
player_input = NodePath("../PlayerInput")
jump_velocity = 12.0
max_speed_debuff = 75.0
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player", "player_input")]
unique_name_in_owner = true
@ -8802,6 +8803,7 @@ script = ExtResource("37_3lpnn")
replication_config = SubResource("SceneReplicationConfig_5amik")
script = ExtResource("38_2cl6u")
[connection signal="damaged" from="." to="PlayerMovement" method="apply_speed_debuff"]
[connection signal="died" from="." to="molikman_ingame/PlayerBasedVisibility" method="reverse_if_own"]
[connection signal="died" from="." to="Camera3D" method="disable"]
[connection signal="died" from="." to="Camera3D/molikman_hands/PlayerBasedVisibility" method="reverse_if_own"]

View file

@ -13,6 +13,7 @@ class_name Player
var passived: bool = false
signal health_changed(to: int)
signal damaged
signal died
const MAX_HP = 100
@ -58,3 +59,4 @@ func depassive() -> void:
func take_damage(damage: int):
hp -= damage
damaged.emit()

View file

@ -2,12 +2,19 @@ extends Node
class_name PlayerMovement
const XZ_PLANE = Vector3.RIGHT + Vector3.BACK
@export var player: Player
@export var player_input: PlayerInput
@export var jump_velocity: float
@export_range(0,100,1,"suffix:%") var max_speed_debuff: float
@export var debuff_time: float = 0.5
var disabled: bool
var speed_debuff: float
var debuff_tween: Tween
func disable() -> void:
disabled = true
@ -21,11 +28,26 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
var input_dir := player_input.direction
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-max_speed*abs(direction.x),max_speed*abs(direction.x))
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta,-max_speed*abs(direction.z),max_speed*abs(direction.z))
var computed_mult : float = (1.-speed_debuff/100.)
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta * computed_mult,-max_speed*abs(direction.x),max_speed*abs(direction.x))
player.velocity.z = clamp(player.velocity.z + direction.z * acceleration * delta * computed_mult,-max_speed*abs(direction.z),max_speed*abs(direction.z))
else:
player.velocity.x = move_toward(player.velocity.x, 0, deceleration*delta)
player.velocity.z = move_toward(player.velocity.z, 0, deceleration*delta)
func jump() -> void:
player.velocity.y = jump_velocity
func apply_speed_debuff():
if debuff_tween:
debuff_tween.kill()
speed_debuff = max_speed_debuff
var xz_velocity: Vector3 = player.velocity * XZ_PLANE
var new_velocity = xz_velocity * (1.-max_speed_debuff/100.)
player.velocity = Vector3(new_velocity.x,player.velocity.y,new_velocity.z)
debuff_tween = create_tween().set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_SINE)
debuff_tween.tween_property(self,"speed_debuff",0,debuff_time)