Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Sprite
- var enemySpeed = 3
- #onready var player_pos = get_parent().get_node('player').get_pos()
- onready var player_node = get_parent().get_node("player")
- var enemy_pos = self.get_pos()
- var enemy_rot = self.get_rot()
- onready var player_pos_rot = get_parent().get_node("player").get_global_pos()
- func _ready():
- set_process(true)
- pass
- func _process(delta):
- var player_pos = get_parent().get_node("player").get_global_pos()
- 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
- self.set_pos(enemy_pos)
- look_at(player_pos)
- player_pos.x += 4
- player_node.set_pos(player_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement