add health component and FollowTarget Enemy Controller and minor changes

This commit is contained in:
2026-05-20 19:31:29 +01:00
parent bceb6c6df8
commit 962bc016a3
9 changed files with 56 additions and 5 deletions
@@ -0,0 +1,17 @@
class_name FollowTargetEnemyController extends SimpleEnemycontroller
@export var target:Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
super._ready()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if target:
direction = sign(target.global_position.x - body.global_position.x )
else:
direction = 0
super._process(delta)
@@ -0,0 +1 @@
uid://12f5ubnmfl0v
@@ -0,0 +1,25 @@
class_name SimpleEnemycontroller extends Node
@export var body: CharacterBody2D
@export var move_res:MovementResouce = MovementResouce.new()
@export var direction:float = 0
@export var handle_movement:bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if body == null:
if get_parent() is CharacterBody2D:
body = get_parent()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if direction:
body.velocity.x = direction * move_res.speed
else:
body.velocity.x = move_toward(body.velocity.x, 0, move_res.speed)
if not body.is_on_floor():
body.velocity.y += move_res.gravity * delta
if handle_movement:
body.move_and_slide()
@@ -0,0 +1 @@
uid://lv8u2g1nxhsp