Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix(camera): one wheel notch zooms 10%, not 0.08%

eyalgolan9a741f5e52ce
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.cs
index 255d4efdf..df55c5db5 100644
--- a/unity/Assets/Scripts/Map/CameraController.cs
+++ b/unity/Assets/Scripts/Map/CameraController.cs
@@ -6,7 +6,7 @@ using UnityEngine.InputSystem;
namespace Statecraft.Game.Map
{
/// <summary>One frame of camera input, in the units the actions give: Pan in [-1, 1] per axis (keys), DragPan in
- /// screen pixels (right-button drag), Zoom in scroll units (positive = in), Orbit in [-1, 1] (Q/E).</summary>
+ /// screen pixels (right-button drag), Zoom in wheel notches (positive = in), Orbit in [-1, 1] (Q/E).</summary>
public struct CameraInput
{
public Vector2 Pan, DragPan; public float Zoom, Orbit;
@@ -26,7 +26,7 @@ namespace Statecraft.Game.Map
public const float MinDistance = 20000f, MaxDistance = 250000f;
public const float PanPerSecond = 0.8f; // distances per second at full key press
public const float DragPanPerPixel = 0.0012f; // distances per pixel of drag
- public const float ZoomPerStep = 0.1f; // fraction of the distance per scroll notch (scroll units are normalised to notches)
+ public const float ZoomPerStep = 0.1f; // fraction of the distance per wheel notch
public const float OrbitDegreesPerSecond = 60f;
public const float MaxFrameSeconds = 0.1f; // a stalled frame (tab in the background) must not fling the camera
@@ -75,7 +75,9 @@ namespace Statecraft.Game.Map
return new CameraInput
{
Pan = panValue, DragPan = dragValue,
- Zoom = Mathf.Clamp(zoomRaw / 120f, -3f, 3f), // browsers report 100-120 per notch; clamp bursts
+ // The Input System's default scroll behaviour (UniformAcrossAllPlatforms) gives 1 per notch on every platform
+ // (measured in headed Chrome on WebGL, Task 24: a 100 px notch -> 1.0); clamp bursts.
+ Zoom = Mathf.Clamp(zoomRaw, -3f, 3f),
Orbit = orbitValue, OverUi = over, DragFromUi = dragFromUi,
};
}
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index 8a142291f..1bddd97ff 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -228,4 +228,26 @@ public class CameraInputTests
}
finally { Object.DestroyImmediate(go); }
}
+
+ // Task 24 (carry 3), measured in headed Chrome on the WebGL build: the Input System's default scroll behaviour
+ // (UniformAcrossAllPlatforms) already gives 1 per wheel notch (Chrome's 100 px notch arrived as 1.0, a 300 px burst
+ // as 3.0), so one notch must zoom by ZoomPerStep (10%), not by a /120 of it.
+ [Test]
+ public void OneWheelNotchZoomsByOneStep()
+ {
+ Assert.AreEqual(UnityEngine.InputSystem.InputSettings.ScrollDeltaBehavior.UniformAcrossAllPlatforms,
+ UnityEngine.InputSystem.InputSystem.settings.scrollDeltaBehavior, "the scroll range this controller assumes");
+ var c = NewController(out var go);
+ try
+ {
+ Assert.AreEqual(1f, c.Gather(Vector2.zero, Vector2.zero, 1f, 0, false, null).Zoom);
+ Assert.AreEqual(-1f, c.Gather(Vector2.zero, Vector2.zero, -1f, 0, false, null).Zoom);
+ Assert.AreEqual(3f, c.Gather(Vector2.zero, Vector2.zero, 7f, 0, false, null).Zoom, "bursts are clamped");
+ var rig = go.GetComponent<CameraRig>();
+ rig.Distance = 120000f;
+ CameraController.Step(rig, c.Gather(Vector2.zero, Vector2.zero, 1f, 0, false, null), 0.016f, Map);
+ Assert.AreEqual(108000f, rig.Distance, 1f);
+ }
+ finally { Object.DestroyImmediate(go); }
+ }
}