Skip to content

Commit 00cc058

Browse files
committed
fix: Fixing an issue with controller inputs
Controller inputs sometimes fire a double "performed" action for no reason. With no matched double "canceled" event, the keyHeld and keyHeldVectors were getting set, causing the probe to move continuously
1 parent b7a687d commit 00cc058

File tree

6 files changed

+145
-50
lines changed

6 files changed

+145
-50
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: c46f07b5ed07e4e92aa78254188d3d10, type: 3}
13+
m_Name: InputSystem.inputsettings
14+
m_EditorClassIdentifier:
15+
m_SupportedDevices: []
16+
m_UpdateMode: 1
17+
m_MaxEventBytesPerUpdate: 5242880
18+
m_MaxQueuedEventsPerUpdate: 1000
19+
m_CompensateForScreenOrientation: 1
20+
m_BackgroundBehavior: 0
21+
m_EditorInputBehaviorInPlayMode: 0
22+
m_DefaultDeadzoneMin: 0.125
23+
m_DefaultDeadzoneMax: 0.925
24+
m_DefaultButtonPressPoint: 0.5
25+
m_ButtonReleaseThreshold: 0.75
26+
m_DefaultTapTime: 0.2
27+
m_DefaultSlowTapTime: 0.5
28+
m_DefaultHoldTime: 0.4
29+
m_TapRadius: 5
30+
m_MultiTapDelayTime: 0.75
31+
m_DisableRedundantEventsMerging: 0
32+
m_ShortcutKeysConsumeInputs: 0
33+
m_iOSSettings:
34+
m_MotionUsage:
35+
m_Enabled: 0
36+
m_Description:

Assets/InputSystem.inputsettings.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/InputSystem/ProbeControlInputActions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public @ProbeControlInputActions()
338338
""name"": """",
339339
""id"": ""5cf77977-d1fc-4f7a-a1a7-a05110343953"",
340340
""path"": ""<Gamepad>/leftStick/up"",
341-
""interactions"": """",
341+
""interactions"": ""Press"",
342342
""processors"": """",
343343
""groups"": """",
344344
""action"": ""Up"",
@@ -347,8 +347,8 @@ public @ProbeControlInputActions()
347347
},
348348
{
349349
""name"": """",
350-
""id"": ""cbbadd5a-0e93-4e47-9bf3-475d4eec4581"",
351-
""path"": ""<Gamepad>/leftStick/down"",
350+
""id"": ""f427774f-6cd6-4ded-859b-779451116d2b"",
351+
""path"": ""<Keyboard>/q"",
352352
""interactions"": """",
353353
""processors"": """",
354354
""groups"": """",
@@ -358,9 +358,9 @@ public @ProbeControlInputActions()
358358
},
359359
{
360360
""name"": """",
361-
""id"": ""f427774f-6cd6-4ded-859b-779451116d2b"",
362-
""path"": ""<Keyboard>/q"",
363-
""interactions"": """",
361+
""id"": ""cbbadd5a-0e93-4e47-9bf3-475d4eec4581"",
362+
""path"": ""<Gamepad>/leftStick/down"",
363+
""interactions"": ""Press"",
364364
""processors"": """",
365365
""groups"": """",
366366
""action"": ""Down"",
@@ -426,7 +426,7 @@ public @ProbeControlInputActions()
426426
""name"": """",
427427
""id"": ""f5df13fa-9091-4f2d-aad7-288ae81fb682"",
428428
""path"": ""<Gamepad>/rightStick/down"",
429-
""interactions"": """",
429+
""interactions"": ""Press"",
430430
""processors"": """",
431431
""groups"": """",
432432
""action"": ""PitchDown"",
@@ -448,7 +448,7 @@ public @ProbeControlInputActions()
448448
""name"": """",
449449
""id"": ""8b1a14bc-69f2-4030-a59b-908a728b5d86"",
450450
""path"": ""<Gamepad>/rightStick/up"",
451-
""interactions"": """",
451+
""interactions"": ""Press"",
452452
""processors"": """",
453453
""groups"": """",
454454
""action"": ""PitchUp"",
@@ -470,7 +470,7 @@ public @ProbeControlInputActions()
470470
""name"": """",
471471
""id"": ""03b3d4b5-2687-417d-9cdd-8386ac5ed855"",
472472
""path"": ""<Gamepad>/rightStick/right"",
473-
""interactions"": """",
473+
""interactions"": ""Press"",
474474
""processors"": """",
475475
""groups"": """",
476476
""action"": ""YawClockwise"",
@@ -492,7 +492,7 @@ public @ProbeControlInputActions()
492492
""name"": """",
493493
""id"": ""993121e9-5acd-4909-9ec1-7a444ebbe00e"",
494494
""path"": ""<Gamepad>/rightStick/left"",
495-
""interactions"": """",
495+
""interactions"": ""Press"",
496496
""processors"": """",
497497
""groups"": """",
498498
""action"": ""YawCounter"",

Assets/InputSystem/ProbeControlInputActions.inputactions

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
"name": "",
317317
"id": "5cf77977-d1fc-4f7a-a1a7-a05110343953",
318318
"path": "<Gamepad>/leftStick/up",
319-
"interactions": "",
319+
"interactions": "Press",
320320
"processors": "",
321321
"groups": "",
322322
"action": "Up",
@@ -325,8 +325,8 @@
325325
},
326326
{
327327
"name": "",
328-
"id": "cbbadd5a-0e93-4e47-9bf3-475d4eec4581",
329-
"path": "<Gamepad>/leftStick/down",
328+
"id": "f427774f-6cd6-4ded-859b-779451116d2b",
329+
"path": "<Keyboard>/q",
330330
"interactions": "",
331331
"processors": "",
332332
"groups": "",
@@ -336,9 +336,9 @@
336336
},
337337
{
338338
"name": "",
339-
"id": "f427774f-6cd6-4ded-859b-779451116d2b",
340-
"path": "<Keyboard>/q",
341-
"interactions": "",
339+
"id": "cbbadd5a-0e93-4e47-9bf3-475d4eec4581",
340+
"path": "<Gamepad>/leftStick/down",
341+
"interactions": "Press",
342342
"processors": "",
343343
"groups": "",
344344
"action": "Down",
@@ -404,7 +404,7 @@
404404
"name": "",
405405
"id": "f5df13fa-9091-4f2d-aad7-288ae81fb682",
406406
"path": "<Gamepad>/rightStick/down",
407-
"interactions": "",
407+
"interactions": "Press",
408408
"processors": "",
409409
"groups": "",
410410
"action": "PitchDown",
@@ -426,7 +426,7 @@
426426
"name": "",
427427
"id": "8b1a14bc-69f2-4030-a59b-908a728b5d86",
428428
"path": "<Gamepad>/rightStick/up",
429-
"interactions": "",
429+
"interactions": "Press",
430430
"processors": "",
431431
"groups": "",
432432
"action": "PitchUp",
@@ -448,7 +448,7 @@
448448
"name": "",
449449
"id": "03b3d4b5-2687-417d-9cdd-8386ac5ed855",
450450
"path": "<Gamepad>/rightStick/right",
451-
"interactions": "",
451+
"interactions": "Press",
452452
"processors": "",
453453
"groups": "",
454454
"action": "YawClockwise",
@@ -470,7 +470,7 @@
470470
"name": "",
471471
"id": "993121e9-5acd-4909-9ec1-7a444ebbe00e",
472472
"path": "<Gamepad>/rightStick/left",
473-
"interactions": "",
473+
"interactions": "Press",
474474
"processors": "",
475475
"groups": "",
476476
"action": "YawCounter",

Assets/Scripts/Pinpoint/Probes/Controllers/CartesianProbeController.cs

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using BrainAtlas;
22
using System;
3+
using System.Collections.Generic;
4+
using System.Reflection;
35
using UnityEngine;
46
using UnityEngine.EventSystems;
7+
using UnityEngine.InputSystem;
58
using UnityEngine.Serialization;
69

710
public class CartesianProbeController : ProbeController
@@ -99,6 +102,7 @@ public override bool Locked
99102
private Vector3 _initialPosition;
100103
private Quaternion _initialRotation;
101104
private float _depth;
105+
private Dictionary<int, bool> _clickDict;
102106

103107
private bool _dirty;
104108

@@ -145,6 +149,7 @@ public override string ZAxisStr
145149
#region Unity
146150
private void Awake()
147151
{
152+
Debug.Log("AWAKE RUNNING");
148153
_depth = _defaultDepth;
149154

150155
_initialPosition = transform.position;
@@ -160,47 +165,92 @@ private void Awake()
160165
var probeControlClick = inputActions.ProbeControl;
161166
probeControlClick.Enable();
162167

168+
// There's something really broken about analog stick "pressing", where the performed event can be fired multiple times
169+
// by pulling the stick back and forward again without going all the way to zero (and triggering "canceled")
170+
//
171+
// Until we can find a fix for this or figure out if this is a bug, we'll fix it here by ensuring that the "Click" call
172+
// for each action type can only ever get called once
173+
_clickDict = new();
174+
for (int i = 0; i <= 13; i++)
175+
_clickDict.Add(i, false);
176+
163177
// Click actions
164-
probeControlClick.Forward.performed += x => Click(ForwardVecWorld);
165-
probeControlClick.Forward.canceled += x => CancelClick(ForwardVecWorld);
166-
probeControlClick.Right.performed += x => Click(RightVecWorld);
167-
probeControlClick.Right.canceled += x => CancelClick(RightVecWorld);
168-
probeControlClick.Back.performed += x => Click(-ForwardVecWorld);
169-
probeControlClick.Back.canceled += x => CancelClick(-ForwardVecWorld);
170-
probeControlClick.Left.performed += x => Click(-RightVecWorld);
171-
probeControlClick.Left.canceled += x => CancelClick(-RightVecWorld);
172-
173-
probeControlClick.Up.performed += x => Click(UpVecWorld);
174-
probeControlClick.Up.canceled += x => CancelClick(UpVecWorld);
175-
probeControlClick.Down.performed += x => Click(-UpVecWorld);
176-
probeControlClick.Down.canceled += x => CancelClick(-UpVecWorld);
177-
178-
probeControlClick.DepthDown.performed += x => Click(DepthVecWorld);
179-
probeControlClick.DepthDown.canceled += x => CancelClick(DepthVecWorld);
180-
probeControlClick.DepthUp.performed += x => Click(-DepthVecWorld);
181-
probeControlClick.DepthUp.canceled += x => CancelClick(-DepthVecWorld);
178+
probeControlClick.Forward.performed += x => ActionHandler(0, ForwardVecWorld, Click);
179+
probeControlClick.Forward.canceled += x => CancelHandler(0, ForwardVecWorld, CancelClick);
180+
probeControlClick.Right.performed += x => ActionHandler(1, RightVecWorld, Click);
181+
probeControlClick.Right.canceled += x => CancelHandler(1, RightVecWorld, CancelClick);
182+
probeControlClick.Back.performed += x => ActionHandler(2, -ForwardVecWorld, Click);
183+
probeControlClick.Back.canceled += x => CancelHandler(2, -ForwardVecWorld, CancelClick);
184+
probeControlClick.Left.performed += x => ActionHandler(3, -RightVecWorld, Click);
185+
probeControlClick.Left.canceled += x => CancelHandler(3, -RightVecWorld, CancelClick);
186+
187+
probeControlClick.Up.performed += x => ActionHandler(4, UpVecWorld, Click);
188+
probeControlClick.Up.canceled += x => CancelHandler(4, UpVecWorld, CancelClick);
189+
probeControlClick.Down.performed += x => ActionHandler(5, -UpVecWorld, Click);
190+
probeControlClick.Down.canceled += x => CancelHandler(5, -UpVecWorld, CancelClick);
191+
192+
probeControlClick.DepthDown.performed += x => ActionHandler(6, DepthVecWorld, Click);
193+
probeControlClick.DepthDown.canceled += x => CancelHandler(6, DepthVecWorld, CancelClick);
194+
probeControlClick.DepthUp.performed += x => ActionHandler(7, -DepthVecWorld, Click);
195+
probeControlClick.DepthUp.canceled += x => CancelHandler(7, -DepthVecWorld, CancelClick);
182196

183197
// Rotate actions
184-
probeControlClick.YawClockwise.performed += x => Rotate(_yawDir);
185-
probeControlClick.YawClockwise.canceled += x => CancelRotate(_yawDir);
186-
probeControlClick.YawCounter.performed += x => Rotate(-_yawDir);
187-
probeControlClick.YawCounter.canceled += x => CancelRotate(-_yawDir);
198+
probeControlClick.YawClockwise.performed += x => ActionHandler(8, _yawDir, Rotate);
199+
probeControlClick.YawClockwise.canceled += x => CancelHandler(8, _yawDir, CancelRotate);
200+
probeControlClick.YawCounter.performed += x => ActionHandler(9, -_yawDir, Rotate);
201+
probeControlClick.YawCounter.canceled += x => CancelHandler(9, -_yawDir, CancelRotate);
188202

189-
probeControlClick.PitchDown.performed += x => Rotate(_pitchDir);
190-
probeControlClick.PitchDown.canceled += x => CancelRotate(_pitchDir);
191-
probeControlClick.PitchUp.performed += x => Rotate(-_pitchDir);
192-
probeControlClick.PitchUp.canceled += x => CancelRotate(-_pitchDir);
203+
probeControlClick.PitchDown.performed += x => ActionHandler(10, _pitchDir, Rotate);
204+
probeControlClick.PitchDown.canceled += x => CancelHandler(10, _pitchDir, CancelRotate);
205+
probeControlClick.PitchUp.performed += x => ActionHandler(11, -_pitchDir, Rotate);
206+
probeControlClick.PitchUp.canceled += x => CancelHandler(11, -_pitchDir, CancelRotate);
193207

194-
probeControlClick.RollClock.performed += x => Rotate(_rollDir);
195-
probeControlClick.RollClock.canceled += x => CancelRotate(_rollDir);
196-
probeControlClick.RollCounter.performed += x => Rotate(-_rollDir);
197-
probeControlClick.RollCounter.canceled += x => CancelRotate(-_rollDir);
208+
probeControlClick.RollClock.performed += x => ActionHandler(12, _rollDir, Rotate);
209+
probeControlClick.RollClock.canceled += x => CancelHandler(12, _rollDir, CancelRotate);
210+
probeControlClick.RollCounter.performed += x => ActionHandler(13, -_rollDir, Rotate);
211+
probeControlClick.RollCounter.canceled += x => CancelHandler(13, -_rollDir, CancelRotate);
198212

199213
probeControlClick.InputControl.performed += x => ToggleControllerLock();
200214

201215
Insertion = new ProbeInsertion(_defaultStart, _defaultAngles, BrainAtlasManager.ActiveReferenceAtlas.AtlasSpace.Name, BrainAtlasManager.ActiveAtlasTransform.Name);
202216
}
203217

218+
#region Awake helpers
219+
private void ActionHandler(int idx, Vector4 dir, Action<Vector4> callback)
220+
{
221+
if (!_clickDict[idx])
222+
{
223+
_clickDict[idx] = true;
224+
callback(dir);
225+
}
226+
}
227+
private void ActionHandler(int idx, Vector3 dir, Action<Vector3> callback)
228+
{
229+
if (!_clickDict[idx])
230+
{
231+
_clickDict[idx] = true;
232+
callback(dir);
233+
}
234+
}
235+
236+
private void CancelHandler(int idx, Vector4 dir, Action<Vector4> callback)
237+
{
238+
if (_clickDict[idx])
239+
{
240+
_clickDict[idx] = false;
241+
callback(dir);
242+
}
243+
}
244+
private void CancelHandler(int idx, Vector3 dir, Action<Vector3> callback)
245+
{
246+
if (_clickDict[idx])
247+
{
248+
_clickDict[idx] = false;
249+
callback(dir);
250+
}
251+
}
252+
#endregion
253+
204254
private void Start()
205255
{
206256
SetProbePosition();

ProjectSettings/EditorBuildSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ EditorBuildSettings:
1010
guid: 01742bb73d3a1b644bfc1c77e581b6bc
1111
m_configObjects:
1212
com.unity.addressableassets: {fileID: 11400000, guid: 7a4fe01e325f0b94f885b0111c032428, type: 2}
13+
com.unity.input.settings: {fileID: 11400000, guid: 6057f25234ce83a4bbb3ae618a501907, type: 2}

0 commit comments

Comments
 (0)