otorp2

my chase player enemy sprite

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