Compare commits

...

4 Commits

Author SHA1 Message Date
mushgunAX 327d96ccd8 Movement by controller 2023-03-14 09:33:16 +08:00
mushgunAX 0b967154ba Merge branch 'main' into ControllerImplementation 2023-03-13 09:51:59 +08:00
mushgunAX d95d0be5e3 Merge branch 'main' into ControllerImplementation 2023-03-10 14:50:25 +08:00
mushgunAX 8755f1753d check on sprinting 2023-03-09 16:04:25 +08:00
6 changed files with 116 additions and 39 deletions

View File

@ -1,4 +1,4 @@
7 10
Controller Look Horizontal Controller Look Horizontal
0 0
0 0
@ -23,6 +23,32 @@ Controller Look Vertical
1 1
19 19
0 0
Drop
0
0
1000
0.2
1000
0
1
2
0
1
13
0
GrabThrow
0
0
1000
0.2
1000
0
1
1
0
1
11
0
Horizontal Horizontal
0 0
0 0
@ -76,6 +102,19 @@ Mouse Look Vertical
0 0
0 0
0 0
Sprint
0
0
1000
0.2
1000
0
1
160
0
1
6
0
Vertical Vertical
0 0
0 0

View File

@ -3184,6 +3184,7 @@
inverseYControls: false inverseYControls: false
pitchUpperClamp: 45 pitchUpperClamp: 45
pitchLowerClamp: 5 pitchLowerClamp: 5
cameraSensitivity: 400
- EID: 9 - EID: 9
Name: PlayerBag Name: PlayerBag
IsActive: true IsActive: true

View File

@ -74,7 +74,7 @@ public class PickAndThrow : Script
itemRidigBody.LinearVelocity = Vector3.Zero; itemRidigBody.LinearVelocity = Vector3.Zero;
itemRidigBody.AngularVelocity = Vector3.Zero; itemRidigBody.AngularVelocity = Vector3.Zero;
if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) if (Input.GetMouseButtonDown(Input.MouseCode.LeftButton) || Input.GetBindingPositiveButtonDown("GrabThrow"))
{ {
pc.isAiming = true; pc.isAiming = true;
pc.camArm.ArmLength = aimingLength; pc.camArm.ArmLength = aimingLength;
@ -83,7 +83,7 @@ public class PickAndThrow : Script
pc.cam.FOV = Settings.cameraFOV + 5; pc.cam.FOV = Settings.cameraFOV + 5;
} }
if (Input.GetMouseButtonUp(Input.MouseCode.LeftButton) && pc.isAiming) if ((Input.GetMouseButtonUp(Input.MouseCode.LeftButton) || Input.GetBindingPositiveButtonUp("GrabThrow")) && pc.isAiming)
{ {
AudioHandler.audioClipHandlers["SFXThrow"].Play(); AudioHandler.audioClipHandlers["SFXThrow"].Play();
itemRidigBody.IsGravityEnabled = true; itemRidigBody.IsGravityEnabled = true;
@ -99,7 +99,7 @@ public class PickAndThrow : Script
timer = 0.0f; timer = 0.0f;
} }
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && !pc.isAiming) if ((Input.GetMouseButtonDown(Input.MouseCode.RightButton) || Input.GetBindingPositiveButtonDown("Drop")) && !pc.isAiming)
{ {
pc.holdItem = false; pc.holdItem = false;
inRange = false; inRange = false;
@ -108,7 +108,7 @@ public class PickAndThrow : Script
ResetItemObject(); ResetItemObject();
} }
if (Input.GetMouseButtonDown(Input.MouseCode.RightButton) && pc.isAiming) if ((Input.GetMouseButtonDown(Input.MouseCode.RightButton) || Input.GetBindingPositiveButtonDown("Drop")) && pc.isAiming)
{ {
pc.isAiming = false; pc.isAiming = false;
pc.cam.FOV = Settings.cameraFOV; pc.cam.FOV = Settings.cameraFOV;
@ -125,7 +125,7 @@ public class PickAndThrow : Script
} }
} }
if (timer > delayTimer && pc && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton)) if (timer > delayTimer && pc && !pc.holdItem && inRange && (Input.GetMouseButtonDown(Input.MouseCode.LeftButton) || Input.GetBindingPositiveButtonDown("GrabThrow")))
{ {
if (pc.currentState == RaccoonStates.WALKING || pc.currentState == RaccoonStates.IDLE) if (pc.currentState == RaccoonStates.WALKING || pc.currentState == RaccoonStates.IDLE)
{ {

View File

@ -103,7 +103,7 @@ public class PlayerController : Script
//Transform check //Transform check
tranform = GetComponent<Transform>(); tranform = GetComponent<Transform>();
if(!tranform) if (!tranform)
Debug.LogError("tranform is MISSING!"); Debug.LogError("tranform is MISSING!");
stateMachine = AddScript<StateMachine>(); stateMachine = AddScript<StateMachine>();
@ -169,7 +169,7 @@ public class PlayerController : Script
if (!pat) if (!pat)
{ {
pat = GetScript<PickAndThrow>(); pat = GetScript<PickAndThrow>();
if(!pat) if (!pat)
Debug.LogError("PickAndThrow is NULL!"); Debug.LogError("PickAndThrow is NULL!");
} }
@ -179,7 +179,7 @@ public class PlayerController : Script
if (pat) if (pat)
cam.FOV = Settings.cameraFOV; cam.FOV = Settings.cameraFOV;
} }
if(!camArm) if (!camArm)
camArm = GetComponentInChildren<CameraArm>(); camArm = GetComponentInChildren<CameraArm>();
@ -211,46 +211,71 @@ public class PlayerController : Script
private void MoveKey() private void MoveKey()
{ {
axisMove = Vector2.Zero; axisMove = Vector2.Zero;
if (Input.GetKey(Input.KeyCode.W))
//Forward/Backward
Vector3 cameraAxisForward = cam.GetForward();
cameraAxisForward.y = 0.0f;
cameraAxisForward.Normalise();
Vector2 vectorForward = new Vector2(cameraAxisForward.x, cameraAxisForward.z);
vectorForward *= Input.GetBindingAxis("Vertical");
axisMove += vectorForward;
//Left/Right
Vector3 cameraAxisSide = cam.GetRight();
cameraAxisSide.y = 0.0f;
cameraAxisSide.Normalise();
Vector2 vectorSide = new Vector2(cameraAxisSide.x, cameraAxisSide.z);
vectorSide *= Input.GetBindingAxis("Horizontal");
axisMove += vectorSide;
/*if (Input.GetBindingAxis("Vertical") > 0.0f)
{ {
Vector3 camerAixs = cam.GetForward(); Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0; camerAixs.y = 0;
camerAixs.Normalise(); camerAixs.Normalise();
axisMove += new Vector2(camerAixs.x, camerAixs.z); Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
vectorForward *= Input.GetBindingAxis("Vertical");
axisMove += vectorForward;
} }
if (Input.GetKey(Input.KeyCode.S)) if (Input.GetBindingAxis("Vertical") < 0.0f)
{ {
Vector3 camerAixs = cam.GetForward(); Vector3 camerAixs = cam.GetForward();
camerAixs.y = 0; camerAixs.y = 0;
camerAixs.Normalise(); camerAixs.Normalise();
axisMove -= new Vector2(camerAixs.x, camerAixs.z); Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
vectorForward *= Input.GetBindingAxis("Vertical");
axisMove += vectorForward;
} }
if (Input.GetKey(Input.KeyCode.A)) if (Input.GetBindingAxis("Horizontal") < 0.0f)
{ {
Vector3 camerAixs = cam.GetRight(); Vector3 camerAixs = cam.GetRight();
camerAixs.y = 0; camerAixs.y = 0;
camerAixs.Normalise(); camerAixs.Normalise();
axisMove -= new Vector2(camerAixs.x, camerAixs.z); Vector2 vectorSide = new Vector2(camerAixs.x, camerAixs.z);
vectorSide *= Input.GetBindingAxis("Horizontal");
axisMove += vectorSide;
} }
if (Input.GetKey(Input.KeyCode.D)) if (Input.GetBindingAxis("Horizontal") > 0.0f)
{ {
Vector3 camerAixs = cam.GetRight(); Vector3 camerAixs = cam.GetRight();
camerAixs.y = 0; camerAixs.y = 0;
camerAixs.Normalise(); camerAixs.Normalise();
axisMove += new Vector2(camerAixs.x, camerAixs.z); Vector2 vectorSide = new Vector2(camerAixs.x, camerAixs.z);
vectorSide *= Input.GetBindingAxis("Horizontal");
axisMove += vectorSide;
} }
axisMove.Normalise(); axisMove.Normalise();*/
isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0; isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0;
if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift)) if (isMoveKeyPress && isGrounded && !Input.GetBindingPositiveButton("Sprint"))
{ {
currentState = RaccoonStates.WALKING; currentState = RaccoonStates.WALKING;
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
stateMachine.SetState(typeof(PlayerWalkState)); stateMachine.SetState(typeof(PlayerWalkState));
} }
@ -258,7 +283,7 @@ public class PlayerController : Script
{ {
currentState = RaccoonStates.IDLE; currentState = RaccoonStates.IDLE;
if(stateMachine && !stateMachine.IsState(typeof(PlayerIdleState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
stateMachine.SetState(typeof(PlayerIdleState)); stateMachine.SetState(typeof(PlayerIdleState));
} }
} }
@ -285,7 +310,7 @@ public class PlayerController : Script
private void Sprint() private void Sprint()
{ {
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded) if (Input.GetBindingPositiveButton("Sprint") && isMoveKeyPress && isGrounded)
{ {
currentState = RaccoonStates.RUNNING; currentState = RaccoonStates.RUNNING;
if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState)))
@ -303,12 +328,12 @@ public class PlayerController : Script
} }
} }
if (Input.GetKeyUp(Input.KeyCode.LeftShift)) if (Input.GetBindingPositiveButtonUp("Sprint"))
{ {
if (isMoveKeyPress) if (isMoveKeyPress)
{ {
currentState = RaccoonStates.WALKING; currentState = RaccoonStates.WALKING;
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
stateMachine.SetState(typeof(PlayerWalkState)); stateMachine.SetState(typeof(PlayerWalkState));
} }
sprintIncreaseOnce = false; sprintIncreaseOnce = false;
@ -321,7 +346,7 @@ public class PlayerController : Script
{ {
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE) if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)
{ {
if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad ) && isGrounded && rb != null) if ((Input.GetBindingPositiveButtonDown("Jump")|| landedOnJumpPad) && isGrounded && rb != null)
{ {
currentState = RaccoonStates.JUMP; currentState = RaccoonStates.JUMP;
if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState)))
@ -348,7 +373,7 @@ public class PlayerController : Script
} }
} }
if (!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space))) if (!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetBindingPositiveButtonUp("Jump")))
{ {
currentState = RaccoonStates.FALLING; currentState = RaccoonStates.FALLING;
if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState))) if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState)))
@ -363,7 +388,7 @@ public class PlayerController : Script
if (isMoveKeyPress && tranform && !isAiming) if (isMoveKeyPress && tranform && !isAiming)
{ {
Quaternion currentRotation = tranform.LocalRotation; Quaternion currentRotation = tranform.LocalRotation;
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(axisMove.x,axisMove.y), 0.0f); Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(axisMove.x, axisMove.y), 0.0f);
tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.FixedDeltaTime); tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.FixedDeltaTime);
} }
else if (camArm && tranform && isAiming) else if (camArm && tranform && isAiming)

View File

@ -19,6 +19,8 @@ namespace SHADE_Scripting
public float pitchUpperClamp = 45.0f; public float pitchUpperClamp = 45.0f;
public float pitchLowerClamp = 5.0f; public float pitchLowerClamp = 5.0f;
public float cameraSensitivity = 400.0f;
protected override void awake() protected override void awake()
{ {
AddComponent<Transform>(); AddComponent<Transform>();
@ -50,7 +52,14 @@ namespace SHADE_Scripting
CameraArm arm = GetComponent<CameraArm>(); CameraArm arm = GetComponent<CameraArm>();
if (arm) if (arm)
{ {
Vector2 vel = Input.GetMouseVelocity(); Vector2 vel = new Vector2();
if (!Input.ControllerInUse)
vel = Input.GetMouseVelocity();
else
{
vel.x = (float)Input.GetBindingAxis("Controller Look Horizontal") * cameraSensitivity;
vel.y = (float)Input.GetBindingAxis("Controller Look Vertical") * cameraSensitivity;
}
if(inverseYControls) if(inverseYControls)
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF; arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
else else

View File

@ -12,6 +12,9 @@ public class MainMenu : Script
protected override void awake() protected override void awake()
{ {
//Load the bindings
Input.LoadBindings();
AudioHandler.audioClipHandlers["BGMMainMenu"] = Audio.CreateAudioClip("event:/Music/main_menu"); AudioHandler.audioClipHandlers["BGMMainMenu"] = Audio.CreateAudioClip("event:/Music/main_menu");
//AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element"); //AudioHandler.audioClipHandlers["SFXMouseDownElement"] = Audio.CreateAudioClip("event:/UI/mouse_down_element");
//AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success"); //AudioHandler.audioClipHandlers["SFXUISuccess"] = Audio.CreateAudioClip("event:/UI/success");