Skip to content

Commit 4d1092a

Browse files
committed
Joysick input for zooming and targeted player movement
1 parent d460cb4 commit 4d1092a

File tree

7 files changed

+128
-18
lines changed

7 files changed

+128
-18
lines changed

Assets/_Project/Input/InputSystem.inputsettings.asset

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_Project/Input/TallyInputSystem.cs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ public @TallyInputSystem()
326326
{
327327
""name"": """",
328328
""id"": ""38da5860-c3a4-4452-b7a5-dc625a0c750c"",
329-
""path"": """",
329+
""path"": ""<Gamepad>/rightStick/x"",
330330
""interactions"": """",
331-
""processors"": """",
331+
""processors"": ""AxisDeadzone"",
332332
""groups"": """",
333333
""action"": ""HorizontalMovement"",
334334
""isComposite"": false,
@@ -337,9 +337,9 @@ public @TallyInputSystem()
337337
{
338338
""name"": """",
339339
""id"": ""0eedeee7-12a6-43cc-8b26-b98282ae10c7"",
340-
""path"": """",
340+
""path"": ""<Gamepad>/rightStick/y"",
341341
""interactions"": """",
342-
""processors"": """",
342+
""processors"": ""AxisDeadzone"",
343343
""groups"": """",
344344
""action"": ""VerticalMovement"",
345345
""isComposite"": false,
@@ -356,6 +356,17 @@ public @TallyInputSystem()
356356
""isComposite"": false,
357357
""isPartOfComposite"": false
358358
},
359+
{
360+
""name"": """",
361+
""id"": ""3e8286f7-c946-4227-ba9a-2eeb14c70dd1"",
362+
""path"": ""<Gamepad>/leftStick/left"",
363+
""interactions"": ""Press"",
364+
""processors"": ""AxisDeadzone(min=0.9)"",
365+
""groups"": """",
366+
""action"": ""SelectLeft"",
367+
""isComposite"": false,
368+
""isPartOfComposite"": false
369+
},
359370
{
360371
""name"": """",
361372
""id"": ""8243ac7f-1b18-40ac-ad62-7c65a80554c0"",
@@ -367,6 +378,17 @@ public @TallyInputSystem()
367378
""isComposite"": false,
368379
""isPartOfComposite"": false
369380
},
381+
{
382+
""name"": """",
383+
""id"": ""bd171bd5-503f-41eb-9ddc-1eac11ab4a4e"",
384+
""path"": ""<Gamepad>/leftStick/right"",
385+
""interactions"": ""Press"",
386+
""processors"": ""AxisDeadzone(min=0.9)"",
387+
""groups"": """",
388+
""action"": ""SelectRight"",
389+
""isComposite"": false,
390+
""isPartOfComposite"": false
391+
},
370392
{
371393
""name"": """",
372394
""id"": ""ffa8e996-cbf6-4c29-8047-ab5ea597c2fc"",
@@ -378,6 +400,17 @@ public @TallyInputSystem()
378400
""isComposite"": false,
379401
""isPartOfComposite"": false
380402
},
403+
{
404+
""name"": """",
405+
""id"": ""c6abec59-4081-475c-bfe0-fd45bdb4dded"",
406+
""path"": ""<Gamepad>/leftStick/up"",
407+
""interactions"": ""Press"",
408+
""processors"": ""AxisDeadzone(min=0.9)"",
409+
""groups"": """",
410+
""action"": ""ZoomIn"",
411+
""isComposite"": false,
412+
""isPartOfComposite"": false
413+
},
381414
{
382415
""name"": """",
383416
""id"": ""53133cea-56df-4dfd-bead-1725b0d50780"",
@@ -388,6 +421,17 @@ public @TallyInputSystem()
388421
""action"": ""ZoomOut"",
389422
""isComposite"": false,
390423
""isPartOfComposite"": false
424+
},
425+
{
426+
""name"": """",
427+
""id"": ""1f09a615-7bc7-45bb-9fc9-14e6e4332c00"",
428+
""path"": ""<Gamepad>/leftStick/down"",
429+
""interactions"": ""Press"",
430+
""processors"": ""AxisDeadzone(min=0.9)"",
431+
""groups"": """",
432+
""action"": ""ZoomOut"",
433+
""isComposite"": false,
434+
""isPartOfComposite"": false
391435
}
392436
]
393437
}

Assets/_Project/Input/TallyInputSystem.inputactions

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@
313313
{
314314
"name": "",
315315
"id": "38da5860-c3a4-4452-b7a5-dc625a0c750c",
316-
"path": "",
316+
"path": "<Gamepad>/rightStick/x",
317317
"interactions": "",
318-
"processors": "",
318+
"processors": "AxisDeadzone",
319319
"groups": "",
320320
"action": "HorizontalMovement",
321321
"isComposite": false,
@@ -324,9 +324,9 @@
324324
{
325325
"name": "",
326326
"id": "0eedeee7-12a6-43cc-8b26-b98282ae10c7",
327-
"path": "",
327+
"path": "<Gamepad>/rightStick/y",
328328
"interactions": "",
329-
"processors": "",
329+
"processors": "AxisDeadzone",
330330
"groups": "",
331331
"action": "VerticalMovement",
332332
"isComposite": false,
@@ -343,6 +343,17 @@
343343
"isComposite": false,
344344
"isPartOfComposite": false
345345
},
346+
{
347+
"name": "",
348+
"id": "3e8286f7-c946-4227-ba9a-2eeb14c70dd1",
349+
"path": "<Gamepad>/leftStick/left",
350+
"interactions": "Press",
351+
"processors": "AxisDeadzone(min=0.9)",
352+
"groups": "",
353+
"action": "SelectLeft",
354+
"isComposite": false,
355+
"isPartOfComposite": false
356+
},
346357
{
347358
"name": "",
348359
"id": "8243ac7f-1b18-40ac-ad62-7c65a80554c0",
@@ -354,6 +365,17 @@
354365
"isComposite": false,
355366
"isPartOfComposite": false
356367
},
368+
{
369+
"name": "",
370+
"id": "bd171bd5-503f-41eb-9ddc-1eac11ab4a4e",
371+
"path": "<Gamepad>/leftStick/right",
372+
"interactions": "Press",
373+
"processors": "AxisDeadzone(min=0.9)",
374+
"groups": "",
375+
"action": "SelectRight",
376+
"isComposite": false,
377+
"isPartOfComposite": false
378+
},
357379
{
358380
"name": "",
359381
"id": "ffa8e996-cbf6-4c29-8047-ab5ea597c2fc",
@@ -365,6 +387,17 @@
365387
"isComposite": false,
366388
"isPartOfComposite": false
367389
},
390+
{
391+
"name": "",
392+
"id": "c6abec59-4081-475c-bfe0-fd45bdb4dded",
393+
"path": "<Gamepad>/leftStick/up",
394+
"interactions": "Press",
395+
"processors": "AxisDeadzone(min=0.9)",
396+
"groups": "",
397+
"action": "ZoomIn",
398+
"isComposite": false,
399+
"isPartOfComposite": false
400+
},
368401
{
369402
"name": "",
370403
"id": "53133cea-56df-4dfd-bead-1725b0d50780",
@@ -375,6 +408,17 @@
375408
"action": "ZoomOut",
376409
"isComposite": false,
377410
"isPartOfComposite": false
411+
},
412+
{
413+
"name": "",
414+
"id": "1f09a615-7bc7-45bb-9fc9-14e6e4332c00",
415+
"path": "<Gamepad>/leftStick/down",
416+
"interactions": "Press",
417+
"processors": "AxisDeadzone(min=0.9)",
418+
"groups": "",
419+
"action": "ZoomOut",
420+
"isComposite": false,
421+
"isPartOfComposite": false
378422
}
379423
]
380424
}

Assets/_Project/Scripts/Effects/CameraManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ public void AddPlayer(string username)
120120
}
121121
}
122122

123+
/// <summary>
124+
/// Gets the camera target
125+
/// </summary>
126+
/// <returns> GameObject being targeted by camera </returns>
127+
public GameObject getCameraTarget()
128+
{
129+
return cameraTarget;
130+
}
131+
132+
123133
/// <summary>
124134
/// Gives exponential graph
125135
/// </summary>

Assets/_Project/Scripts/Movement/MovePositionWanderComplex.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class MovePositionWanderComplex : PhysicsBase {
2020
public float rotateTimeElapsed = 0;
2121
public float rotateDuration = 200;
2222

23+
private CameraManager cameraManager;
2324

2425
private void Start ()
2526
{
@@ -28,6 +29,8 @@ private void Start ()
2829

2930
// first wander point
3031
wayPoint = ReturnNewWanderPoint ();
32+
33+
cameraManager = GetComponentInParent<Player>().cameraManager;
3134
}
3235

3336
protected override void Update ()
@@ -51,9 +54,17 @@ void FixedUpdate ()
5154
wayPoint = ReturnNewWanderPoint ();
5255
}
5356

54-
55-
// get direction
56-
direction = transform.TransformDirection (Vector2.right);
57+
// if player input is happening and the current object is targeted
58+
if (playerInput.magnitude != 0 && cameraManager.getCameraTarget().Equals(gameObject))
59+
{
60+
// get player input
61+
direction = playerInput;
62+
}
63+
else
64+
{
65+
// get direction
66+
direction = transform.TransformDirection(Vector2.right);
67+
}
5768

5869
// distance to move each frame = normalized distance vector * speed * time since last frame
5970
Vector3 step = direction * thrust * Time.deltaTime;
@@ -94,10 +105,6 @@ void RotateTowardsTarget2D ()
94105
rotateTimeElapsed += Time.deltaTime;
95106
}
96107

97-
98-
99-
100-
101108
/**
102109
* Show ray between two points
103110
*/
@@ -107,8 +114,8 @@ void ShowRayBetweenPoints (Vector3 p1, Vector3 p2)
107114
}
108115

109116
/**
110-
* Return a new target wander point within bounds of collider
111-
*/
117+
* Return a new target wander point within bounds of collider
118+
*/
112119
Vector3 ReturnNewWanderPoint ()
113120
{
114121
bool pointWithin = false; // is the point within the collider?

Assets/_Project/Scripts/Players/Player.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class Player : MonoBehaviour {
2121
public AnimController animControllerScript; // animation controller script
2222

2323

24+
// Camera manager
25+
public CameraManager cameraManager;
26+
2427
private void Awake ()
2528
{
2629
StartCoroutine (StartChecks ());

Assets/_Project/Scripts/Players/PlayerManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public void CreateNewPlayer (string username, string avatarPath)
138138
obj.transform.parent = gameObject.transform;
139139
// finaly, add to dict
140140
playerDict.Add (username, obj);
141+
// sets a reference to the cameraManager
142+
obj.GetComponent<Player>().cameraManager = cameraManager;
141143

142144
// Allow the player to be selected by the camera
143145
cameraManager.AddPlayer(username);

0 commit comments

Comments
 (0)