summaryrefslogtreecommitdiff
path: root/godot/scripts/cameras/player_firstperson.gd
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2022-09-07 14:07:30 -0400
committerAnson Bridges <bridges.anson@gmail.com>2022-09-07 14:07:30 -0400
commitc232b92e2dde1277324d1f89d0e75ae641e4ac3b (patch)
treee11a5dd52f259c1cc7345baa40b372b304417f00 /godot/scripts/cameras/player_firstperson.gd
parenta0967ebe815cd229b69fb9578f2288b95b2ddb28 (diff)
reorganized, ladders, vehicle control
Diffstat (limited to 'godot/scripts/cameras/player_firstperson.gd')
-rw-r--r--godot/scripts/cameras/player_firstperson.gd33
1 files changed, 33 insertions, 0 deletions
diff --git a/godot/scripts/cameras/player_firstperson.gd b/godot/scripts/cameras/player_firstperson.gd
new file mode 100644
index 0000000..ace49e6
--- /dev/null
+++ b/godot/scripts/cameras/player_firstperson.gd
@@ -0,0 +1,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