-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamRoot.gd
More file actions
46 lines (35 loc) · 1.48 KB
/
CamRoot.gd
File metadata and controls
46 lines (35 loc) · 1.48 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
extends Node3D
signal set_cam_rotation(_cam_rotation : float)
@export var player : CharacterBody3D
@onready var yaw_node = $CamYaw
@onready var pitch_node = $CamYaw/CamPitch
@onready var spring_arm = $CamYaw/CamPitch/SpringArm3D
@onready var camera = $CamYaw/CamPitch/SpringArm3D/Camera3D
var yaw : float = 0
var pitch : float = 0
var yaw_sensitivity : float = 0.07
var pitch_sensitivity : float = 0.07
var yaw_acceleration : float = 15
var pitch_acceleration : float = 15
var pitch_max : float = 75
var pitch_min : float = -55
var tween : Tween
var position_offset : Vector3 = Vector3(0, 1.3, 0)
var position_offset_target : Vector3 = Vector3(0, 1.3, 0)
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
top_level = true
func _input(event):
if event is InputEventMouseMotion:
yaw += -event.relative.x * yaw_sensitivity
pitch += event.relative.z * pitch_sensitivity
func _physics_process(delta):
position_offset = lerp(position_offset, position_offset_target, 4 * delta)
global_position = lerp(global_position, player.global_position + position_offset, 18 * delta)
pitch = clamp(pitch, pitch_min, pitch_max)
yaw_node.rotation_degrees.y = lerp(yaw_node.rotation_degrees.y, yaw, yaw_acceleration * delta)
pitch_node.rotation_degrees.x = lerp(pitch_node.rotation_degrees.x, pitch, pitch_acceleration * delta)
#if you don't want to lerp, set them directly
#yaw_node.rotation_degrees.y = yaw
#pitch_node.rotation_degrees.x = pitch
set_cam_rotation.emit(yaw_node.rotation.y)