CyberTower/scripts/attacker.gd

18 lines
392 B
GDScript3
Raw Normal View History

2024-02-16 12:35:30 +00:00
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()