Advertisement
otorp2

from root enemy chase plyr

Apr 10th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1.  
  2. extends Node2D
  3. var enemySpeed = 1
  4.  
  5. onready var enemy_pos = get_node("enemy").get_pos()
  6. onready var player_pos = get_node("player").get_pos()
  7. onready var enemy_node = get_node("enemy")
  8.  
  9.  
  10. func _ready():
  11.  
  12. set_process(true)
  13. pass
  14.  
  15. func _process(delta):
  16.  
  17. var dx = player_pos.x - enemy_pos.x
  18. var dy = player_pos.y - enemy_pos.y
  19. var distance = sqrt(dx * dx + dy * dy)
  20. enemy_pos.x = enemy_pos.x + dx / distance * enemySpeed
  21. enemy_pos.y= enemy_pos.y + dy / distance * enemySpeed
  22. enemy_node.set_pos(enemy_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement