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