mirror of
https://github.com/BotChain-Robots/ui.git
synced 2026-07-08 15:07:22 +02:00
Fixed up some issues with camera rotation and removed functionality where moving camera disables servo and dc ui panels
This commit is contained in:
@@ -11,14 +11,6 @@ public class ModuleSelector : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
// If user is moving the camera, deselect current module
|
||||
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) ||
|
||||
Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
|
||||
{
|
||||
ClearSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
// Ignore clicks over UI
|
||||
|
||||
@@ -4055,10 +4055,13 @@ MonoBehaviour:
|
||||
panSpeed: 3.5
|
||||
zoomSpeed: 10
|
||||
moveSmoothTime: 0.12
|
||||
orbitSpeed: 150
|
||||
orbitSpeed: 20
|
||||
minPitch: -80
|
||||
maxPitch: 80
|
||||
orbitSmoothTime: 0.08
|
||||
lockCursorWhileOrbiting: 1
|
||||
maxMouseDelta: 40
|
||||
orbitSmoothing: 0.08
|
||||
lookAtDuration: 0.25
|
||||
homeDuration: 0.35
|
||||
--- !u!114 &963194231
|
||||
|
||||
@@ -18,11 +18,19 @@ public class UserCameraControl : MonoBehaviour
|
||||
public float moveSmoothTime = 0.12f; // higher = snappier, lower = floatier
|
||||
|
||||
[Header("Orbit")]
|
||||
public float orbitSpeed = 180f; // degrees/sec per pixel-ish delta
|
||||
public float orbitSpeed = 20f; // degrees/sec per pixel-ish delta
|
||||
public float minPitch = -20f;
|
||||
public float maxPitch = 80f;
|
||||
public float orbitSmoothTime = 0.08f;
|
||||
|
||||
[Header("Orbit Feel")]
|
||||
public bool lockCursorWhileOrbiting = true;
|
||||
public float maxMouseDelta = 40f; // clamps rare huge spikes
|
||||
public float orbitSmoothing = 0.08f; // 0 = no smoothing, ~0.05-0.15 feels nice
|
||||
|
||||
Vector2 orbitDeltaSmoothed;
|
||||
Vector2 orbitDeltaVel;
|
||||
|
||||
[Header("Look / Home Smooth")]
|
||||
public float lookAtDuration = 0.25f;
|
||||
public float homeDuration = 0.35f;
|
||||
@@ -84,35 +92,52 @@ public class UserCameraControl : MonoBehaviour
|
||||
orbiting = true;
|
||||
SetCursor(eyeCursor);
|
||||
|
||||
// stop any scripted rotation so user has control
|
||||
StopLookRoutine();
|
||||
|
||||
SyncAnglesFromTransform();
|
||||
lastMouse = (Vector2)Input.mousePosition;
|
||||
|
||||
yawDeltaSmoothed = pitchDeltaSmoothed = 0f;
|
||||
yawDeltaVel = pitchDeltaVel = 0f;
|
||||
if (lockCursorWhileOrbiting)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
orbitDeltaSmoothed = Vector2.zero;
|
||||
orbitDeltaVel = Vector2.zero;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(1))
|
||||
{
|
||||
orbiting = false;
|
||||
|
||||
if (lockCursorWhileOrbiting)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
orbitDeltaSmoothed = Vector2.zero;
|
||||
orbitDeltaVel = Vector2.zero;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!orbiting) return;
|
||||
|
||||
float dt = Time.unscaledDeltaTime;
|
||||
// Use Input axes while locked (stable, no screen-edge issues)
|
||||
float dx = Input.GetAxisRaw("Mouse X");
|
||||
float dy = Input.GetAxisRaw("Mouse Y");
|
||||
|
||||
Vector2 mouse = (Vector2)Input.mousePosition;
|
||||
Vector2 delta = mouse - lastMouse;
|
||||
lastMouse = mouse;
|
||||
// Clamp rare spikes (frame hitch / window focus changes)
|
||||
dx = Mathf.Clamp(dx, -maxMouseDelta, maxMouseDelta);
|
||||
dy = Mathf.Clamp(dy, -maxMouseDelta, maxMouseDelta);
|
||||
|
||||
float targetYawDelta = delta.x * orbitSpeed * dt;
|
||||
float targetPitchDelta = -delta.y * orbitSpeed * dt;
|
||||
Vector2 targetDelta = new Vector2(dx, dy);
|
||||
|
||||
yawDeltaSmoothed = Mathf.SmoothDamp(yawDeltaSmoothed, targetYawDelta, ref yawDeltaVel, orbitSmoothTime);
|
||||
pitchDeltaSmoothed = Mathf.SmoothDamp(pitchDeltaSmoothed, targetPitchDelta, ref pitchDeltaVel, orbitSmoothTime);
|
||||
if (orbitSmoothing > 0f)
|
||||
orbitDeltaSmoothed = Vector2.SmoothDamp(orbitDeltaSmoothed, targetDelta, ref orbitDeltaVel, orbitSmoothing);
|
||||
else
|
||||
orbitDeltaSmoothed = targetDelta;
|
||||
|
||||
yaw += yawDeltaSmoothed;
|
||||
pitch += pitchDeltaSmoothed;
|
||||
yaw += orbitDeltaSmoothed.x * orbitSpeed;
|
||||
pitch -= orbitDeltaSmoothed.y * orbitSpeed;
|
||||
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
||||
|
||||
transform.rotation = Quaternion.Euler(pitch, yaw, 0f);
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 664693941061d4a4ab8a0a945db827f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
Reference in New Issue
Block a user