You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.2 KiB

  1. extends Spatial
  2. # look stats
  3. var lookSensitivity : float = 15.0
  4. var minLookAngle : float = -20.0
  5. var maxLookAngle : float = 75.0
  6. # vectors
  7. var mouseDelta = Vector2()
  8. # components
  9. onready var player = get_parent()
  10. # called when the node is initialized
  11. func _ready ():
  12. on_player_input_change(Controller.player_input_enabled)
  13. Controller.connect("player_input_change", self, "on_player_input_change")
  14. # called when an input is detected
  15. func _input (event):
  16. # set "mouseDelta" when we move our mouse
  17. if Controller.player_input_enabled and event is InputEventMouseMotion:
  18. mouseDelta = event.relative
  19. # called every frame
  20. func _process (delta):
  21. if Controller.player_input_enabled:
  22. # get the rotation to apply to the camera and player
  23. var rot = Vector3(mouseDelta.y, mouseDelta.x, 0) * lookSensitivity * delta
  24. # camera vertical rotation
  25. rotation_degrees.x += rot.x
  26. rotation_degrees.x = clamp(rotation_degrees.x, minLookAngle, maxLookAngle)
  27. # player horizontal rotation
  28. player.rotation_degrees.y -= rot.y
  29. # clear the mouse movement vector
  30. mouseDelta = Vector2()
  31. func on_player_input_change(value):
  32. print(value)
  33. if value:
  34. Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  35. else:
  36. Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)