feat: add knockback functionality; add the hp to the slime;

This commit is contained in:
2026-09-24 22:22:42 +02:00
parent 2aad0915e3
commit 20c127e11d
3 changed files with 19 additions and 6 deletions
+5 -2
View File
@@ -1,6 +1,9 @@
extends CharacterBody2D
@export var speed: int = 300
@export var acceleration: float = 2
@export var HP: int = 2
var target: Node2D
func _physics_process(delta):
@@ -13,7 +16,8 @@ func move_slime():
var distance_to_player: Vector2
distance_to_player = target.global_position - global_position
var direction_normal: Vector2 = distance_to_player.normalized()
velocity = direction_normal * speed
#velocity = direction_normal * speed
velocity = velocity.move_toward(direction_normal * speed, acceleration)
func animate_slime():
var normal_velocity: Vector2 = velocity.normalized()
@@ -26,7 +30,6 @@ func animate_slime():
elif normal_velocity.y < -0.707:
$AnimatedSprite2D.play("move_up")
func _on_player_detect_area_body_entered(body):
if body is Player:
target = body