add enemy hitbox and refactor to characterBody2d
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user