new terrain plugin
This commit is contained in:
29
demo/src/CameraManager.gd
Normal file
29
demo/src/CameraManager.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends Node3D
|
||||
|
||||
const CAMERA_MAX_PITCH: float = deg_to_rad(70)
|
||||
const CAMERA_MIN_PITCH: float = deg_to_rad(-89.9)
|
||||
const CAMERA_RATIO: float = .625
|
||||
|
||||
@export var mouse_sensitivity: float = .002
|
||||
@export var mouse_y_inversion: float = -1.0
|
||||
|
||||
@onready var _camera_yaw: Node3D = self
|
||||
@onready var _camera_pitch: Node3D = %Arm
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
|
||||
func _input(p_event: InputEvent) -> void:
|
||||
if p_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
rotate_camera(p_event.relative)
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
|
||||
|
||||
func rotate_camera(p_relative:Vector2) -> void:
|
||||
_camera_yaw.rotation.y -= p_relative.x * mouse_sensitivity
|
||||
_camera_yaw.orthonormalize()
|
||||
_camera_pitch.rotation.x += p_relative.y * mouse_sensitivity * CAMERA_RATIO * mouse_y_inversion
|
||||
_camera_pitch.rotation.x = clamp(_camera_pitch.rotation.x, CAMERA_MIN_PITCH, CAMERA_MAX_PITCH)
|
||||
Reference in New Issue
Block a user