Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Sprite
- var enemySpeed = 3
- onready var player_node = get_parent().get_node("player")
- func _ready():
- set_process(true)
- pass
- func _process(delta):
- var my_pos = get_pos()
- var player_pos = player_node.get_pos()
- var dx = player_pos.x - my_pos.x
- var dy = player_pos.y - my_pos.y
- var distance = sqrt(dx * dx + dy * dy)
- my_pos.x += dx / distance * enemySpeed
- my_pos.y += dy / distance * enemySpeed
- set_pos(my_pos)
- player_pos.x += 4
- player_node.set_pos(player_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement