Cinematic camera
This commit is contained in:
parent
89210f59ea
commit
84f8cf5d76
@ -2,24 +2,34 @@ extends CharacterBody3D
|
||||
|
||||
@export var camera: Camera3D
|
||||
|
||||
@export var SPEED = 4.0
|
||||
var SPEED = 2.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const MOUSE_SENSITIVITY = 0.004
|
||||
|
||||
const ROTATION_SPEED := 4.0 # How fast to interpolate (higher = snappier)
|
||||
var target_rotation := Vector2.ZERO # x = pitch, y = yaw
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
assert(camera != null, "Forgot to set camera in editor")
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
## Implements [member Portal3D.ON_TELEPORT_CALLBACK]
|
||||
func on_teleport(portal: Portal3D) -> void:
|
||||
print("on_teleport: player position - ",self.global_position)
|
||||
# Initialize target rotation from current rotation
|
||||
target_rotation.y = rotation.y
|
||||
target_rotation.x = camera.rotation.x
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
rotate_y(-event.screen_relative.x * MOUSE_SENSITIVITY)
|
||||
camera.rotate_x(-event.screen_relative.y * MOUSE_SENSITIVITY)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(80))
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
target_rotation.y -= event.relative.x * MOUSE_SENSITIVITY
|
||||
target_rotation.x -= event.relative.y * MOUSE_SENSITIVITY
|
||||
target_rotation.x = clamp(target_rotation.x, deg_to_rad(-80), deg_to_rad(80))
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
# Smoothly interpolate current rotation toward target
|
||||
rotation.y = lerp_angle(rotation.y, target_rotation.y, delta * ROTATION_SPEED)
|
||||
camera.rotation.x = lerp_angle(camera.rotation.x, target_rotation.x, delta * ROTATION_SPEED)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var right: Vector3 = (global_transform.basis.x * Vector3(1, 0, 1)).normalized()
|
||||
|
Loading…
Reference in New Issue
Block a user