Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. const SPEED_MULTIPLIER = 2
  4. const STRAFE_MULTIPLIER = 1.5
  5.  
  6. func _ready():
  7. set_fixed_process(true)
  8.  
  9. func _fixed_process(delta):
  10. update()
  11. # rotation
  12. var mouse_pos = get_viewport().get_mouse_pos()
  13. var rot = get_angle_to(mouse_pos) + self.get_rot()
  14. set_rot(rot)
  15.  
  16. # movement
  17. var player_pos = self.get_pos()
  18. if Input.is_action_pressed("strafe_left"):
  19. move((mouse_pos - player_pos).normalized().tangent() * STRAFE_MULTIPLIER)
  20. if Input.is_action_pressed("strafe_right"):
  21. move((player_pos - mouse_pos).normalized().tangent() * STRAFE_MULTIPLIER)
  22. if Input.is_action_pressed("move_forward"):
  23. move((mouse_pos - player_pos).normalized() * SPEED_MULTIPLIER)
  24. if Input.is_action_pressed("move_backward"):
  25. move((player_pos - mouse_pos).normalized() * SPEED_MULTIPLIER)
  26.  
  27. # actions
  28. if Input.is_action_pressed("primary_fire"):
  29. var space_state = get_world_2d().get_direct_space_state()
  30. var result = space_state.intersect_ray(player_pos, mouse_pos, [ self ])
  31. if (not result.empty()):
  32. print("Hit at point: ",result.position)
  33.  
  34. if Input.is_action_pressed("jump"):
  35. print ("JUMPING")
  36.  
  37. func _draw():
  38. draw_line(self.get_pos(), get_viewport().get_mouse_pos(), Color(255, 0, 0), 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement