18 lines
392 B
GDScript3
18 lines
392 B
GDScript3
|
extends Enemy
|
||
|
|
||
|
@export var speed = 800
|
||
|
@export var friction = 0.9
|
||
|
|
||
|
@export var target: Node2D
|
||
|
|
||
|
func deal_move(delta):
|
||
|
if target:
|
||
|
var angle = get_angle_to(target.position)
|
||
|
var direction = Vector2(cos(angle), sin(angle))
|
||
|
velocity = velocity.move_toward(direction * speed, speed * delta)
|
||
|
velocity = velocity * friction
|
||
|
|
||
|
func _physics_process(delta):
|
||
|
deal_move(delta)
|
||
|
move_and_slide()
|