Advertisement
otorp2

from enemy node enemy chase playr

Apr 10th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1.  
  2. extends Sprite
  3. onready var player_pos = get_parent().get_node("player").get_pos()
  4. var enemySpeed = 2
  5. func _ready():
  6. set_process(true)
  7.  
  8. # Initialization here
  9. pass
  10. func _process(delta):
  11. var enemy_pos = get_pos()
  12.  
  13. #
  14.  
  15. #
  16. var dirx = player_pos.x - enemy_pos.x
  17. var diry = player_pos.y - enemy_pos.y
  18. # var dy = player_pos.y - get_pos().y
  19. #
  20. var hyp = sqrt(dirx * dirx + diry * diry)
  21. enemy_pos.x = enemy_pos.x + dirx / hyp * 2
  22. enemy_pos.y = enemy_pos.y + diry / hyp * 2
  23. set_pos(enemy_pos)
  24. print(enemy_pos.x )
  25.  
  26.  
  27.  
  28. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement