Files
2D_Game_test/PhysicsObjects/HandStatue/HandStatue.gd

33 lines
932 B
GDScript

extends RigidBody2D
@export var initial_impulse:Vector2 = Vector2(0,0)
@export var damage_speed:int = 50
@export var max_speed:int = 150
@export var push_strength:int = 20
@onready var last_velocity:Vector2 = Vector2(0,0)
func _physics_process(delta):
last_velocity = get_linear_velocity()
if last_velocity.length() > damage_speed:
set_modulate(Color("8e2325"))
else:
set_modulate(Color("ffffff"))
if last_velocity.length() > max_speed:
set_linear_velocity(get_linear_velocity().normalized() * max_speed)
last_velocity.length()
func _on_body_entered(body):
if body.is_in_group("player"):
if last_velocity.length() > damage_speed:
body.player_hit.is_player_hit = true
body.player_hit.hit_velocity = last_velocity.normalized() * push_strength
body.health_changed_func(-1)
# set_freeze_enabled(true)
# await get_tree().create_timer(0.5).timeout
set_sleeping(true)
# set_freeze_enabled(false)