Advertisement
otorp2

chase with simple lookat

Mar 20th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 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. var enemy_rot = self.get_rot()
  8. onready var player_pos_rot = get_parent().get_node("player").get_global_pos()
  9.  
  10. func _ready():
  11. set_process(true)
  12. pass
  13.  
  14. func _process(delta):
  15. var player_pos = get_parent().get_node("player").get_global_pos()
  16. var dx = player_pos.x - enemy_pos.x
  17. var dy = player_pos.y - enemy_pos.y
  18. var distance = sqrt(dx * dx + dy * dy)
  19. enemy_pos.x = enemy_pos.x + dx / distance * enemySpeed
  20. enemy_pos.y = enemy_pos.y + dy / distance * enemySpeed
  21. self.set_pos(enemy_pos)
  22. look_at(player_pos)
  23.  
  24. player_pos.x += 4
  25. player_node.set_pos(player_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement