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.
 
 

42 lines
958 B

  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 an input is detected
  11. func _input (event):
  12. # set "mouseDelta" when we move our mouse
  13. if event is InputEventMouseMotion:
  14. mouseDelta = event.relative
  15. # called every frame
  16. func _process (delta):
  17. # get the rotation to apply to the camera and player
  18. var rot = Vector3(mouseDelta.y, mouseDelta.x, 0) * lookSensitivity * delta
  19. # camera vertical rotation
  20. rotation_degrees.x += rot.x
  21. rotation_degrees.x = clamp(rotation_degrees.x, minLookAngle, maxLookAngle)
  22. # player horizontal rotation
  23. player.rotation_degrees.y -= rot.y
  24. # clear the mouse movement vector
  25. mouseDelta = Vector2()
  26. # called when the node is initialized
  27. func _ready ():
  28. # hide the mouse cursor
  29. Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)