GodotCourse/week5/updated_project/scripts/badguy.gd

25 lines
557 B
GDScript

extends Area2D
const speed = 60
var direction = 1
@onready var cast_right = $CastRight
@onready var cast_left = $CastLeft
@onready var sprite = $AnimatedSprite2D
@onready var game = $".."
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if cast_right.is_colliding():
direction = -1
sprite.flip_h = true
if cast_left.is_colliding():
direction = 1
sprite.flip_h = false
position.x += direction * speed * delta
func _on_body_entered(body):
if body.is_in_group("player"):
game.playerDeath()