Advertisement
otorp2

Yeolds chase player from enemy sprite

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