Movement by controller
This commit is contained in:
parent
0b967154ba
commit
327d96ccd8
|
@ -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
|
||||||
|
|
|
@ -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,58 +211,71 @@ public class PlayerController : Script
|
||||||
private void MoveKey()
|
private void MoveKey()
|
||||||
{
|
{
|
||||||
axisMove = Vector2.Zero;
|
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();
|
Vector3 camerAixs = cam.GetForward();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
Vector2 forwardMove = new Vector2(camerAixs.x, camerAixs.z);
|
Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
|
||||||
forwardMove *= Input.GetBindingAxis("Vertical");
|
vectorForward *= Input.GetBindingAxis("Vertical");
|
||||||
//axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += vectorForward;
|
||||||
axisMove += forwardMove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.S) || Input.GetBindingAxisRaw("Vertical") < 0.0f)
|
if (Input.GetBindingAxis("Vertical") < 0.0f)
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetForward();
|
Vector3 camerAixs = cam.GetForward();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
Vector2 forwardMove = new Vector2(camerAixs.x, camerAixs.z);
|
Vector2 vectorForward = new Vector2(camerAixs.x, camerAixs.z);
|
||||||
forwardMove *= Input.GetBindingAxis("Vertical");
|
vectorForward *= Input.GetBindingAxis("Vertical");
|
||||||
//axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += vectorForward;
|
||||||
axisMove += forwardMove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.A) || Input.GetBindingAxisRaw("Horizontal") < 0.0f)
|
if (Input.GetBindingAxis("Horizontal") < 0.0f)
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetRight();
|
Vector3 camerAixs = cam.GetRight();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
Vector2 sideMove = new Vector2(camerAixs.x, camerAixs.z);
|
Vector2 vectorSide = new Vector2(camerAixs.x, camerAixs.z);
|
||||||
sideMove *= Input.GetBindingAxis("Horizontal");
|
vectorSide *= Input.GetBindingAxis("Horizontal");
|
||||||
//axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += vectorSide;
|
||||||
axisMove += sideMove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.D) || Input.GetBindingAxisRaw("Horizontal") > 0.0f)
|
if (Input.GetBindingAxis("Horizontal") > 0.0f)
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetRight();
|
Vector3 camerAixs = cam.GetRight();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
Vector2 sideMove = new Vector2(camerAixs.x, camerAixs.z);
|
Vector2 vectorSide = new Vector2(camerAixs.x, camerAixs.z);
|
||||||
sideMove *= Input.GetBindingAxis("Horizontal");
|
vectorSide *= Input.GetBindingAxis("Horizontal");
|
||||||
//axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += vectorSide;
|
||||||
axisMove += sideMove;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//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) && Input.GetBindingAxisRaw("Sprint") == 0.0f)
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +310,7 @@ public class PlayerController : Script
|
||||||
|
|
||||||
private void Sprint()
|
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;
|
currentState = RaccoonStates.RUNNING;
|
||||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState)))
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState)))
|
||||||
|
@ -315,12 +328,12 @@ public class PlayerController : Script
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift) || Input.GetBindingPositiveButtonUp("Sprint"))
|
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;
|
||||||
|
@ -333,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 || Input.GetBindingPositiveButtonDown("Jump")) && 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)))
|
||||||
|
@ -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;
|
currentState = RaccoonStates.FALLING;
|
||||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState)))
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState)))
|
||||||
stateMachine.SetState(typeof(PlayerFallState));
|
stateMachine.SetState(typeof(PlayerFallState));
|
||||||
|
@ -374,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)
|
||||||
|
|
|
@ -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>();
|
||||||
|
@ -55,9 +57,8 @@ namespace SHADE_Scripting
|
||||||
vel = Input.GetMouseVelocity();
|
vel = Input.GetMouseVelocity();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO REPLACE HARDCODED MULTIPLIER
|
vel.x = (float)Input.GetBindingAxis("Controller Look Horizontal") * cameraSensitivity;
|
||||||
vel.x = (float)Input.GetBindingAxis("Controller Look Horizontal") * 300.0f;
|
vel.y = (float)Input.GetBindingAxis("Controller Look Vertical") * cameraSensitivity;
|
||||||
vel.y = (float)Input.GetBindingAxis("Controller Look Vertical") * 300.0f;
|
|
||||||
}
|
}
|
||||||
if(inverseYControls)
|
if(inverseYControls)
|
||||||
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
||||||
|
|
Loading…
Reference in New Issue