Improve controller movement

This commit is contained in:
BuyMyMojo 2023-03-04 07:34:48 +11:00
parent 4e96a88306
commit 161aece83e
5 changed files with 12 additions and 10 deletions

4
.erp
View file

@ -5,7 +5,7 @@
<resetOnSceneChange>false</resetOnSceneChange> <resetOnSceneChange>false</resetOnSceneChange>
<debugMode>false</debugMode> <debugMode>false</debugMode>
<EditorClosed>true</EditorClosed> <EditorClosed>true</EditorClosed>
<LastTimestamp>1677880402</LastTimestamp> <LastTimestamp>1677876493</LastTimestamp>
<LastSessionID>7184246594242351147</LastSessionID> <LastSessionID>2115309888051293429</LastSessionID>
<Errored>false</Errored> <Errored>false</Errored>
</ERPSettings> </ERPSettings>

View file

@ -180,7 +180,7 @@ public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
""id"": ""545341dc-a1a1-47e8-a08d-84a68957f048"", ""id"": ""545341dc-a1a1-47e8-a08d-84a68957f048"",
""path"": ""<Gamepad>/leftStick"", ""path"": ""<Gamepad>/leftStick"",
""interactions"": """", ""interactions"": """",
""processors"": """", ""processors"": ""StickDeadzone(min=0.5)"",
""groups"": """", ""groups"": """",
""action"": ""Move"", ""action"": ""Move"",
""isComposite"": false, ""isComposite"": false,
@ -200,7 +200,7 @@ public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
{ {
""name"": """", ""name"": """",
""id"": ""f3791e57-b19a-4a65-ba91-e9f4484e7581"", ""id"": ""f3791e57-b19a-4a65-ba91-e9f4484e7581"",
""path"": ""<Gamepad>/buttonWest"", ""path"": ""<Gamepad>/buttonSouth"",
""interactions"": """", ""interactions"": """",
""processors"": """", ""processors"": """",
""groups"": """", ""groups"": """",
@ -222,7 +222,7 @@ public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
{ {
""name"": """", ""name"": """",
""id"": ""915cd8bb-a4cc-4a75-b7ee-327c965ac8c2"", ""id"": ""915cd8bb-a4cc-4a75-b7ee-327c965ac8c2"",
""path"": ""<Gamepad>/buttonSouth"", ""path"": ""<Gamepad>/buttonWest"",
""interactions"": """", ""interactions"": """",
""processors"": """", ""processors"": """",
""groups"": """", ""groups"": """",

View file

@ -158,7 +158,7 @@
"id": "545341dc-a1a1-47e8-a08d-84a68957f048", "id": "545341dc-a1a1-47e8-a08d-84a68957f048",
"path": "<Gamepad>/leftStick", "path": "<Gamepad>/leftStick",
"interactions": "", "interactions": "",
"processors": "", "processors": "StickDeadzone(min=0.5)",
"groups": "", "groups": "",
"action": "Move", "action": "Move",
"isComposite": false, "isComposite": false,
@ -178,7 +178,7 @@
{ {
"name": "", "name": "",
"id": "f3791e57-b19a-4a65-ba91-e9f4484e7581", "id": "f3791e57-b19a-4a65-ba91-e9f4484e7581",
"path": "<Gamepad>/buttonWest", "path": "<Gamepad>/buttonSouth",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": "",
@ -200,7 +200,7 @@
{ {
"name": "", "name": "",
"id": "915cd8bb-a4cc-4a75-b7ee-327c965ac8c2", "id": "915cd8bb-a4cc-4a75-b7ee-327c965ac8c2",
"path": "<Gamepad>/buttonSouth", "path": "<Gamepad>/buttonWest",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": "",

View file

@ -35,6 +35,8 @@ public class GameInput : MonoBehaviour
playerInputActions = new PlayerInputActions(); playerInputActions = new PlayerInputActions();
if (PlayerPrefs.HasKey(PLAYER_PREFS_BINDINGS)) if (PlayerPrefs.HasKey(PLAYER_PREFS_BINDINGS))
{ {
playerInputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString(PLAYER_PREFS_BINDINGS)); playerInputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString(PLAYER_PREFS_BINDINGS));

View file

@ -138,7 +138,7 @@ public class Player : MonoBehaviour, IKitchenObjectParent
// attempt only X move // attempt only X move
Vector3 moveDirX = new Vector3(moveDir.x, 0, 0).normalized; Vector3 moveDirX = new Vector3(moveDir.x, 0, 0).normalized;
canMove = moveDir.x != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance); canMove = (moveDir.x < -.5f || moveDir.x > +.5f) && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
// if able to move on X then change moveDir to X // if able to move on X then change moveDir to X
if (canMove) if (canMove)
@ -149,7 +149,7 @@ public class Player : MonoBehaviour, IKitchenObjectParent
{ {
// cannot move on X so attempt to move on Z // cannot move on X so attempt to move on Z
Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized; Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized;
canMove = moveDir.z != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance); canMove = (moveDir.z < -.5f || moveDir.z > +.5f) && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance);
// if able to move on Z then change moveDir to Z // if able to move on Z then change moveDir to Z
if (canMove) if (canMove)