CyberTower/scripts/attacker.gd
2024-02-16 20:35:30 +08:00

18 lines
392 B
GDScript

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()