Movement by controller
This commit is contained in:
parent
0b967154ba
commit
327d96ccd8
|
@ -3184,6 +3184,7 @@
|
|||
inverseYControls: false
|
||||
pitchUpperClamp: 45
|
||||
pitchLowerClamp: 5
|
||||
cameraSensitivity: 400
|
||||
- EID: 9
|
||||
Name: PlayerBag
|
||||
IsActive: true
|
||||
|
|
|
@ -211,54 +211,67 @@ public class PlayerController : Script
|
|||
private void MoveKey()
|
||||
{
|
||||
axisMove = Vector2.Zero;
|
||||
if (Input.GetKey(Input.KeyCode.W) || Input.GetBindingAxisRaw("Vertical") > 0.0f)
|
||||
|
||||
//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();
|
||||
camerAixs.y = 0;
|
||||
camerAixs.Normalise();
|
||||
Vector2 forwardMove = new Vector2(camerAixs.x, camerAixs.z);
|
||||
forwardMove *= Input.GetBindingAxis("Vertical");
|
||||
//axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
||||
axisMove += forwardMove;
|
||||
Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
|
||||
vectorForward *= Input.GetBindingAxis("Vertical");
|
||||
axisMove += vectorForward;
|
||||
}
|
||||
|
||||
if (Input.GetKey(Input.KeyCode.S) || Input.GetBindingAxisRaw("Vertical") < 0.0f)
|
||||
if (Input.GetBindingAxis("Vertical") < 0.0f)
|
||||
{
|
||||
Vector3 camerAixs = cam.GetForward();
|
||||
camerAixs.y = 0;
|
||||
camerAixs.Normalise();
|
||||
Vector2 forwardMove = new Vector2(camerAixs.x, camerAixs.z);
|
||||
forwardMove *= Input.GetBindingAxis("Vertical");
|
||||
//axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
||||
axisMove += forwardMove;
|
||||
Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
|
||||
vectorForward *= Input.GetBindingAxis("Vertical");
|
||||
axisMove += vectorForward;
|
||||
}
|
||||
|
||||
if (Input.GetKey(Input.KeyCode.A) || Input.GetBindingAxisRaw("Horizontal") < 0.0f)
|
||||
if (Input.GetBindingAxis("Horizontal") < 0.0f)
|
||||
{
|
||||
Vector3 camerAixs = cam.GetRight();
|
||||
camerAixs.y = 0;
|
||||
camerAixs.Normalise();
|
||||
Vector2 sideMove = new Vector2(camerAixs.x, camerAixs.z);
|
||||
sideMove *= Input.GetBindingAxis("Horizontal");
|
||||
//axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
||||
axisMove += sideMove;
|
||||
Vector2 vectorSide = new Vector2(camerAixs.x, camerAixs.z);
|
||||
vectorSide *= Input.GetBindingAxis("Horizontal");
|
||||
axisMove += vectorSide;
|
||||
}
|
||||
|
||||
if (Input.GetKey(Input.KeyCode.D) || Input.GetBindingAxisRaw("Horizontal") > 0.0f)
|
||||
if (Input.GetBindingAxis("Horizontal") > 0.0f)
|
||||
{
|
||||
Vector3 camerAixs = cam.GetRight();
|
||||
camerAixs.y = 0;
|
||||
camerAixs.Normalise();
|
||||
Vector2 sideMove = new Vector2(camerAixs.x, camerAixs.z);
|
||||
sideMove *= Input.GetBindingAxis("Horizontal");
|
||||
//axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
||||
axisMove += sideMove;
|
||||
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;
|
||||
|
||||
if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift) && Input.GetBindingAxisRaw("Sprint") == 0.0f)
|
||||
if (isMoveKeyPress && isGrounded && !Input.GetBindingPositiveButton("Sprint"))
|
||||
{
|
||||
currentState = RaccoonStates.WALKING;
|
||||
|
||||
|
@ -297,7 +310,7 @@ public class PlayerController : Script
|
|||
|
||||
private void Sprint()
|
||||
{
|
||||
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded && Input.GetBindingAxisRaw("Sprint") > 0.0f)
|
||||
if (Input.GetBindingPositiveButton("Sprint") && isMoveKeyPress && isGrounded)
|
||||
{
|
||||
currentState = RaccoonStates.RUNNING;
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState)))
|
||||
|
@ -315,7 +328,7 @@ public class PlayerController : Script
|
|||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift) || Input.GetBindingPositiveButtonUp("Sprint"))
|
||||
if (Input.GetBindingPositiveButtonUp("Sprint"))
|
||||
{
|
||||
if (isMoveKeyPress)
|
||||
{
|
||||
|
@ -333,7 +346,7 @@ public class PlayerController : Script
|
|||
{
|
||||
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)
|
||||
{
|
||||
if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad || Input.GetBindingPositiveButtonDown("Jump")) && isGrounded && rb != null)
|
||||
if ((Input.GetBindingPositiveButtonDown("Jump")|| landedOnJumpPad) && isGrounded && rb != null)
|
||||
{
|
||||
currentState = RaccoonStates.JUMP;
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState)))
|
||||
|
@ -360,7 +373,8 @@ public class PlayerController : Script
|
|||
}
|
||||
}
|
||||
|
||||
if(!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space) || Input.GetBindingPositiveButtonUp("Jump")))
|
||||
if (!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetBindingPositiveButtonUp("Jump")))
|
||||
{
|
||||
currentState = RaccoonStates.FALLING;
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState)))
|
||||
stateMachine.SetState(typeof(PlayerFallState));
|
||||
|
|
|
@ -19,6 +19,8 @@ namespace SHADE_Scripting
|
|||
public float pitchUpperClamp = 45.0f;
|
||||
public float pitchLowerClamp = 5.0f;
|
||||
|
||||
public float cameraSensitivity = 400.0f;
|
||||
|
||||
protected override void awake()
|
||||
{
|
||||
AddComponent<Transform>();
|
||||
|
@ -55,9 +57,8 @@ namespace SHADE_Scripting
|
|||
vel = Input.GetMouseVelocity();
|
||||
else
|
||||
{
|
||||
//TODO REPLACE HARDCODED MULTIPLIER
|
||||
vel.x = (float)Input.GetBindingAxis("Controller Look Horizontal") * 300.0f;
|
||||
vel.y = (float)Input.GetBindingAxis("Controller Look Vertical") * 300.0f;
|
||||
vel.x = (float)Input.GetBindingAxis("Controller Look Horizontal") * cameraSensitivity;
|
||||
vel.y = (float)Input.GetBindingAxis("Controller Look Vertical") * cameraSensitivity;
|
||||
}
|
||||
if(inverseYControls)
|
||||
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
||||
|
|
Loading…
Reference in New Issue