More camera tweaking
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class_name OverworldCamera extends Camera3D
|
||||
|
||||
enum CameraMode { FREE, CENTERED }
|
||||
enum CameraMode { FREE, CENTERED, MANUAL_CENTER }
|
||||
|
||||
# const COLLISION_MARGIN:float = 0.1
|
||||
const COLLISION_MARGIN:float = 0
|
||||
@@ -28,6 +28,7 @@ const COLLISION_MARGIN:float = 0
|
||||
@export var centeredAcceleration:float = 180.0
|
||||
@export var centeredMaxYawDiff:float = 120.0
|
||||
@export var centeredPitch:float = 30.0
|
||||
@export var manualCenterMultiplier:float = 10.0
|
||||
|
||||
@export_category("Collision")
|
||||
@export_flags_3d_physics var collisionMask:int = 1
|
||||
@@ -84,9 +85,9 @@ func _process(delta:float) -> void:
|
||||
_pitch += _mouseDelta.y * mouseSensitivity * SETTINGS.cameraSpeedMouse * yMult
|
||||
_mouseDelta = Vector2.ZERO
|
||||
|
||||
# center_camera input → switch to CENTERED immediately
|
||||
# center_camera input → switch to MANUAL_CENTER immediately
|
||||
if Input.is_action_just_pressed("center_camera"):
|
||||
_mode = CameraMode.CENTERED
|
||||
_mode = CameraMode.MANUAL_CENTER
|
||||
|
||||
# In FREE mode, accumulate time toward auto-centering while the player is moving
|
||||
if _mode == CameraMode.FREE:
|
||||
@@ -102,16 +103,28 @@ func _process(delta:float) -> void:
|
||||
# In CENTERED mode, accelerate a yaw velocity toward behind the player (using
|
||||
# actual movement velocity for direction) then friction-decay when idle —
|
||||
# mirrors how controller input works so there's no sudden stop.
|
||||
if _mode == CameraMode.CENTERED:
|
||||
if _mode == CameraMode.CENTERED or _mode == CameraMode.MANUAL_CENTER:
|
||||
var centerBody := targetNode as CharacterBody3D
|
||||
var vel3d:Vector3 = Vector3.ZERO if centerBody == null else centerBody.velocity
|
||||
var behindYaw:float = 0.0
|
||||
var hasTarget:bool = false
|
||||
|
||||
if vel3d.length_squared() > 0.1:
|
||||
var behindYaw:float = rad_to_deg(atan2(-vel3d.x, -vel3d.z))
|
||||
behindYaw = rad_to_deg(atan2(-vel3d.x, -vel3d.z))
|
||||
hasTarget = true
|
||||
elif _mode == CameraMode.MANUAL_CENTER and targetNode != null:
|
||||
behindYaw = rad_to_deg(targetNode.rotation.y)
|
||||
hasTarget = true
|
||||
|
||||
if hasTarget:
|
||||
var centerYawDiff:float = fposmod(behindYaw - _yaw + 180.0, 360.0) - 180.0
|
||||
if _mode == CameraMode.MANUAL_CENTER and abs(centerYawDiff) < centeredMaxYawDiff * 0.05:
|
||||
_mode = CameraMode.FREE
|
||||
var totalAngle:float = abs(centerYawDiff) + abs(centeredPitch - _pitch)
|
||||
var dynamicRate:float = minf(centeredFollowRate * (1.0 + totalAngle / 90.0), centeredMaxFollowRate)
|
||||
var speedMult:float = manualCenterMultiplier if _mode == CameraMode.MANUAL_CENTER else 1.0
|
||||
var dynamicRate:float = minf(centeredFollowRate * (1.0 + totalAngle / 90.0), centeredMaxFollowRate) * speedMult
|
||||
if abs(centerYawDiff) <= centeredMaxYawDiff:
|
||||
_centerVelocity = move_toward(_centerVelocity, centerYawDiff * dynamicRate, centeredAcceleration * delta)
|
||||
_centerVelocity = move_toward(_centerVelocity, centerYawDiff * dynamicRate, centeredAcceleration * speedMult * delta)
|
||||
var tPitch:float = minf(dynamicRate * 3.0 * delta, 1.0)
|
||||
_pitch = lerpf(_pitch, centeredPitch, tPitch)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user