add enemy hitbox and refactor to characterBody2d

This commit is contained in:
2025-10-21 21:22:08 +01:00
parent 1fcc9a0a35
commit f9a218159c
7 changed files with 78 additions and 6 deletions

View File

@@ -2,3 +2,4 @@ extends Node2D
const COLLISION_SHAPE_2D = "CollisionShape2D"
const CHARACTER_BODY_2D = "CharacterBody2D"
const ANIMATED_SPRITE_2D = "AnimatedSprite2D"

View File

@@ -1,4 +1,4 @@
extends Node2D
extends CharacterBody2D
@export var speed = 60
@@ -9,7 +9,11 @@ var direction = 1
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
func _physics_process(delta: float) -> void:
# Apply gravity
if not is_on_floor():
velocity += get_gravity() * delta
if ray_cast_right.is_colliding():
direction = -1
animated_sprite.flip_h = true
@@ -19,3 +23,9 @@ func _process(delta: float) -> void:
animated_sprite.flip_h = false
position.x += direction * speed * delta
move_and_slide()
func _on_hit_box_killed() -> void:
queue_free()