Skip to content

Commit 922a5d0

Browse files
committed
"Follow World" - When not following the car, start from the car position.
1 parent fa02078 commit 922a5d0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

LowLevel/Sandbox/Assets/Scenes/Benchmark/LargeWorld/LargeWorld.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class LargeWorld : MonoBehaviour
2222
private PhysicsWheelJoint m_RearWheelJoint;
2323
private PhysicsWheelJoint m_FrontWheelJoint;
2424

25-
private FloatField m_WorldPosition;
26-
private FloatField m_WorldSize;
25+
private FloatField m_WorldPositionField;
26+
private FloatField m_WorldSizeField;
2727

2828
private void OnEnable()
2929
{
@@ -77,19 +77,26 @@ private void SetupOptions()
7777
// Follow Car.
7878
var followCar = root.Q<Toggle>("follow-car");
7979
followCar.value = m_FollowCar;
80-
followCar.RegisterValueChangedCallback(evt => { m_FollowCar = evt.newValue; });
80+
followCar.RegisterValueChangedCallback(evt =>
81+
{
82+
m_FollowCar = evt.newValue;
83+
84+
// If we're no longer following the car then set the current camera position to the car position.
85+
if (!m_FollowCar)
86+
m_CameraPosition = new Vector2(m_FrontWheelJoint.bodyA.position.x, m_CameraPosition.y);
87+
});
8188

8289
// Camera Pan Speed.
8390
var cameraPanSpeed = root.Q<Slider>("camera-pan-speed");
8491
cameraPanSpeed.value = m_CameraPanSpeed;
8592
cameraPanSpeed.RegisterValueChangedCallback(evt => { m_CameraPanSpeed = evt.newValue; });
8693

8794
// World Position.
88-
m_WorldPosition = root.Q<FloatField>("world-position");
95+
m_WorldPositionField = root.Q<FloatField>("world-position");
8996

9097
// World Size.
91-
m_WorldSize = root.Q<FloatField>("world-size");
92-
m_WorldSize.value = m_GridSize * m_GridCount / 1000.0f;
98+
m_WorldSizeField = root.Q<FloatField>("world-size");
99+
m_WorldSizeField.value = m_GridSize * m_GridCount / 1000.0f;
93100

94101
// Reset Scene.
95102
var resetScene = root.Q<Button>("reset-scene");
@@ -272,7 +279,7 @@ private void Update()
272279
m_CameraManipulator.CameraPosition = new Vector2(m_FrontWheelJoint.bodyA.position.x, m_CameraManipulator.CameraPosition.y);
273280

274281
// Show world position.
275-
m_WorldPosition.value = m_CameraManipulator.CameraPosition.x / 1000.0f;
282+
m_WorldPositionField.value = m_CameraManipulator.CameraPosition.x / 1000.0f;
276283
}
277284

278285
private void SetCarSpeed(float speed)

0 commit comments

Comments
 (0)