M1: fix PlayerDriver input for New-only Input System (Keyboard.current)
Project ships Active Input Handling = Input System (New) only, so the drafted legacy Input.GetAxisRaw would throw InvalidOperationException at runtime. Read WASD/arrows off Keyboard.current instead — no restart, no action asset needed. (TreadPart needs the same swap when the bot lands.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1be4730756
commit
26abf15902
1 changed files with 13 additions and 6 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
namespace Jankenbots.Net
|
namespace Jankenbots.Net
|
||||||
{
|
{
|
||||||
|
|
@ -83,12 +84,18 @@ namespace Jankenbots.Net
|
||||||
// host, for capsules it doesn't own) skips input entirely — IsOwner is the gate.
|
// host, for capsules it doesn't own) skips input entirely — IsOwner is the gate.
|
||||||
if (!IsOwner) return;
|
if (!IsOwner) return;
|
||||||
|
|
||||||
// Throwaway-prototype input: legacy Input axes are perfectly fine here. WASD / arrows
|
// Throwaway-prototype input via the new Input System. The project ships New-only, so
|
||||||
// / left stick map to Horizontal + Vertical out of the box. (The project ships the new
|
// legacy UnityEngine.Input.GetAxis would THROW at runtime — read WASD / arrow keys
|
||||||
// Input System, but its compatibility mode feeds these same axes, so this Just Works
|
// straight off the current keyboard instead. No action asset needed for an M1 smoke test.
|
||||||
// for M1 without authoring an action asset.)
|
var kb = Keyboard.current;
|
||||||
float strafe = Input.GetAxisRaw("Horizontal"); // A/D, left-stick X
|
float strafe = 0f, fwd = 0f;
|
||||||
float fwd = Input.GetAxisRaw("Vertical"); // W/S, left-stick Y
|
if (kb != null)
|
||||||
|
{
|
||||||
|
if (kb.aKey.isPressed || kb.leftArrowKey.isPressed) strafe -= 1f; // left
|
||||||
|
if (kb.dKey.isPressed || kb.rightArrowKey.isPressed) strafe += 1f; // right
|
||||||
|
if (kb.wKey.isPressed || kb.upArrowKey.isPressed) fwd += 1f; // forward
|
||||||
|
if (kb.sKey.isPressed || kb.downArrowKey.isPressed) fwd -= 1f; // back
|
||||||
|
}
|
||||||
|
|
||||||
Vector2 input = new Vector2(strafe, fwd);
|
Vector2 input = new Vector2(strafe, fwd);
|
||||||
// Normalize so diagonal input isn't ~1.4x faster; keep magnitude for analog sticks.
|
// Normalize so diagonal input isn't ~1.4x faster; keep magnitude for analog sticks.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue