-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCamera.gd
32 lines (25 loc) · 859 Bytes
/
Camera.gd
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
extends Spatial
onready var player = get_parent()
var camrot_h = 0
var camrot_v = 0
var cam_v_max = 75
var cam_v_min = -55
var h_sensitivity = 0.1
var v_sensitivity = 0.1
var h_acceleration = 10
var v_acceleration = 10
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$h/v/Camera.add_exception(player)
func _input(event):
if event is InputEventMouseMotion &&!get_node("../").targeting:
camrot_h += -event.relative.x * h_sensitivity
camrot_v += event.relative.y * v_sensitivity
func _physics_process(delta):
camrot_v = clamp(camrot_v, cam_v_min, cam_v_max)
if !get_node("../").targeting:
$h.rotation_degrees.y = lerp($h.rotation_degrees.y, camrot_h, delta * h_acceleration)
$h/v.rotation_degrees.x = lerp($h/v.rotation_degrees.x, camrot_v, delta * v_acceleration)
else:
camrot_h = $h.rotation_degrees.y
camrot_v = 0