blob: ace49e663f0b46c59ee0054c5a14a6ccf4b4646e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
extends Camera
var mouse_axis := Vector2()
var mouse_sensitivity = 12.0
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
current = false
func _input(event):
if current:
if Input.is_action_just_pressed("menu"): #toggle mouse capture on esc
if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
mouse_axis = event.relative
if mouse_axis.length() > 0:
var horizontal: float = -mouse_axis.x * (mouse_sensitivity / 100)
var vertical: float = -mouse_axis.y * (mouse_sensitivity / 100)
mouse_axis = Vector2()
get_parent().rotate_y(deg2rad(horizontal))
rotate_x(deg2rad(vertical))
var temp_rot: Vector3 = rotation_degrees
temp_rot.x = clamp(temp_rot.x, -90, 90)
get_parent().animationcontroller.rpc("lean",-1*temp_rot.x/90)
rotation_degrees = temp_rot
|