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
|
||||
|
|
|
@ -46,7 +46,7 @@ public class PlayerController : Script
|
|||
private float oldForce;
|
||||
private float maxOldVel;
|
||||
private bool sprintIncreaseOnce = false;
|
||||
|
||||
|
||||
public Vector2 axisMove { get; set; }
|
||||
|
||||
public bool isMoveKeyPress { get; set; }
|
||||
|
@ -103,7 +103,7 @@ public class PlayerController : Script
|
|||
|
||||
//Transform check
|
||||
tranform = GetComponent<Transform>();
|
||||
if(!tranform)
|
||||
if (!tranform)
|
||||
Debug.LogError("tranform is MISSING!");
|
||||
|
||||
stateMachine = AddScript<StateMachine>();
|
||||
|
@ -169,20 +169,20 @@ public class PlayerController : Script
|
|||
if (!pat)
|
||||
{
|
||||
pat = GetScript<PickAndThrow>();
|
||||
if(!pat)
|
||||
if (!pat)
|
||||
Debug.LogError("PickAndThrow is NULL!");
|
||||
}
|
||||
|
||||
if (!cam)
|
||||
{
|
||||
{
|
||||
cam = GetComponentInChildren<Camera>();
|
||||
if (pat)
|
||||
cam.FOV = Settings.cameraFOV;
|
||||
}
|
||||
if(!camArm)
|
||||
if (!camArm)
|
||||
camArm = GetComponentInChildren<CameraArm>();
|
||||
|
||||
|
||||
|
||||
|
||||
GotCaught();
|
||||
Rotation();
|
||||
|
@ -211,66 +211,79 @@ 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;
|
||||
|
||||
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
||||
stateMachine.SetState(typeof(PlayerWalkState));
|
||||
}
|
||||
|
||||
if (!isMoveKeyPress && isGrounded)
|
||||
{
|
||||
{
|
||||
currentState = RaccoonStates.IDLE;
|
||||
|
||||
if(stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
||||
stateMachine.SetState(typeof(PlayerIdleState));
|
||||
}
|
||||
}
|
||||
|
@ -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,12 +328,12 @@ public class PlayerController : Script
|
|||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift) || Input.GetBindingPositiveButtonUp("Sprint"))
|
||||
if (Input.GetBindingPositiveButtonUp("Sprint"))
|
||||
{
|
||||
if (isMoveKeyPress)
|
||||
{
|
||||
{
|
||||
currentState = RaccoonStates.WALKING;
|
||||
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
||||
stateMachine.SetState(typeof(PlayerWalkState));
|
||||
}
|
||||
sprintIncreaseOnce = false;
|
||||
|
@ -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)))
|
||||
|
@ -352,7 +365,7 @@ public class PlayerController : Script
|
|||
}
|
||||
|
||||
if (landedOnJumpPad)
|
||||
{
|
||||
{
|
||||
v.y *= jumpPadMultiplayer;
|
||||
landedOnJumpPad = false;
|
||||
}
|
||||
|
@ -360,12 +373,13 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Rotation()
|
||||
|
@ -374,7 +388,7 @@ public class PlayerController : Script
|
|||
if (isMoveKeyPress && tranform && !isAiming)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if (camArm && tranform && isAiming)
|
||||
|
@ -392,10 +406,10 @@ public class PlayerController : Script
|
|||
{
|
||||
//check player vel.y if its close to zero its on the ground
|
||||
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
|
||||
{
|
||||
{
|
||||
isGrounded = true;
|
||||
if (currentState == RaccoonStates.FALLING)
|
||||
{
|
||||
{
|
||||
currentState = RaccoonStates.LANDED;
|
||||
if (stateMachine && !stateMachine.IsState(typeof(PlayerLandState)))
|
||||
stateMachine.SetState(typeof(PlayerLandState));
|
||||
|
|
|
@ -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