Skip to content

Commit 8cf40ed

Browse files
committed
fix: keep in mind camera might be moved by external script
1 parent c214c3e commit 8cf40ed

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/UI/Panels/FreeCamPanel.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public FreeCamPanel(UIBase owner) : base(owner)
8585
public static GameObject followObject = null;
8686
public static Vector3 followObjectLastPosition = Vector3.zero;
8787
public static Quaternion followObjectLastRotation = Quaternion.identity;
88+
public static Vector3 lastKnownPosition = Vector3.zero;
8889

8990
private static FreecamCursorUnlocker freecamCursorUnlocker = null;
9091

@@ -723,13 +724,21 @@ internal void Update()
723724
}
724725
Transform transform = FreeCamPanel.CameraContainer;
725726

727+
var inputDelta = Vector3.zero;
726728
if (!FreeCamPanel.blockFreecamMovementToggle.isOn && !FreeCamPanel.cameraPathMover.playingPath && FreeCamPanel.connector?.IsActive != true) {
727-
ProcessInput();
729+
inputDelta = ProcessInput();
728730
}
729731

730-
if (FreeCamPanel.followObject != null){
732+
if (FreeCamPanel.followObject != null){
731733
// position update
732-
transform.position += FreeCamPanel.followObject.transform.position - FreeCamPanel.followObjectLastPosition;
734+
var positionDelta = FreeCamPanel.followObject.transform.position - FreeCamPanel.followObjectLastPosition;
735+
736+
if (FreeCamPanel.lastKnownPosition != Vector3.zero)
737+
{
738+
//TODO: check delta
739+
positionDelta -= transform.position - (FreeCamPanel.lastKnownPosition + inputDelta);
740+
}
741+
transform.position += positionDelta;
733742

734743
if (FreeCamPanel.followRotationToggle.isOn){
735744
// rotation update
@@ -745,10 +754,12 @@ internal void Update()
745754
FreeCamPanel.connector?.ExecuteCameraCommand(transform);
746755

747756
FreeCamPanel.UpdatePositionInput();
757+
758+
FreeCamPanel.lastKnownPosition = FreeCamPanel.followObject ? transform.position : Vector3.zero;
748759
}
749760
}
750761

751-
internal void ProcessInput(){
762+
internal Vector3 ProcessInput(){
752763
FreeCamPanel.currentUserCameraPosition = transform.position;
753764
FreeCamPanel.currentUserCameraRotation = transform.rotation;
754765

@@ -761,24 +772,26 @@ internal void ProcessInput(){
761772
speedModifier = 0.1f;
762773

763774
moveSpeed *= speedModifier;
775+
776+
var delta = Vector3.zero;
764777

765778
if (IInputManager.GetKey(ConfigManager.Left_1.Value) || IInputManager.GetKey(ConfigManager.Left_2.Value))
766-
transform.position += transform.right * -1 * moveSpeed;
779+
delta += transform.right * -1 * moveSpeed;
767780

768781
if (IInputManager.GetKey(ConfigManager.Right_1.Value) || IInputManager.GetKey(ConfigManager.Right_2.Value))
769-
transform.position += transform.right * moveSpeed;
782+
delta += transform.right * moveSpeed;
770783

771784
if (IInputManager.GetKey(ConfigManager.Forwards_1.Value) || IInputManager.GetKey(ConfigManager.Forwards_2.Value))
772-
transform.position += transform.forward * moveSpeed;
785+
delta += transform.forward * moveSpeed;
773786

774787
if (IInputManager.GetKey(ConfigManager.Backwards_1.Value) || IInputManager.GetKey(ConfigManager.Backwards_2.Value))
775-
transform.position += transform.forward * -1 * moveSpeed;
788+
delta += transform.forward * -1 * moveSpeed;
776789

777790
if (IInputManager.GetKey(ConfigManager.Up.Value))
778-
transform.position += transform.up * moveSpeed;
791+
delta += transform.up * moveSpeed;
779792

780793
if (IInputManager.GetKey(ConfigManager.Down.Value))
781-
transform.position += transform.up * -1 * moveSpeed;
794+
delta += transform.up * -1 * moveSpeed;
782795

783796
if (IInputManager.GetKey(ConfigManager.Tilt_Left.Value))
784797
transform.Rotate(0, 0, moveSpeed * 10, Space.Self);
@@ -840,6 +853,8 @@ internal void ProcessInput(){
840853
}
841854

842855
FreeCamPanel.previousMousePosition = IInputManager.MousePosition;
856+
transform.position += delta;
857+
return delta;
843858
}
844859
}
845860

0 commit comments

Comments
 (0)