clowder/tscn/dog.gd

28 lines
678 B
GDScript3
Raw Normal View History

2024-03-06 22:05:35 +01:00
extends CharacterBody2D
@onready var plr = get_tree().current_scene.get_node("plr")
const SPEED = 300
func _physics_process(delta):
# Add the gravity.
if position.distance_to(plr.position) <= 200:
$AnimationPlayer.current_animation = "attack"
set_process(true)
func _ready():
set_process(false)
func _process(delta):
var dir = (plr.position - self.global_position).normalized()
velocity = dir * SPEED
if not round(dir.x) == 0:
$body.scale.x = round(dir.x)
move_and_slide()
func die():
var emitter = preload("res://tscn/enemyhitbox.tscn").instantiate()
get_parent().add_child(emitter)
emitter.position = self.position
emitter.emitting = true
queue_free()