Implemented Crouch walking

This commit is contained in:
Melbyj1125
2022-04-08 15:21:24 -05:00
parent 562b64b160
commit fdc77ada48
9 changed files with 135 additions and 63 deletions

View File

@@ -274,7 +274,7 @@ public class AerialStateManager : NetworkBehaviour
}
else if(Physics.Raycast(groundRay, out groundHit, moveController.height + groundSlantDistance) && !jumpPressed){
if(Vector3.Dot(groundHit.normal, transform.up) > 0f){
//Debug.Log("On a Slant");
Debug.Log("On a Slant");
// Debug.Log("The grounds Normal" + groundHit.normal);
moveController.Move(groundHit.normal * 20 * Time.deltaTime);
mSM.CancelMomentum();

View File

@@ -220,6 +220,41 @@ public class MoveStateManager : NetworkBehaviour
}
}
public void CrouchMovement(){
//Keyboard inputs
//Checks if movement keys have been pressed and calculates correct vector
if(currentState == CrouchWalkState){
float curSpeed = PlayerSpeed();
if(curSpeed != 0){
moveX = transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * 2;
moveZ = transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * 2;
}
else{
moveX = Vector3.zero;
moveZ = Vector3.zero;
}
vel = moveX + moveZ;
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
driftVel = Vector3.Lerp(driftVel, moveXZ, 10 * Time.deltaTime);
if(currentState == GrappleAirState){
driftVel = Vector3.zero;
}
if(driftVel != Vector3.zero){
playerModel.transform.rotation = Quaternion.LookRotation(driftVel.normalized);
}
//Actually move he player
moveController.Move(driftVel);
}
else{
moveController.Move(Vector3.zero);
}
}
//Wasd movement using player speed
public void DirectionalMovement(){
//Keyboard inputs
@@ -272,11 +307,6 @@ public class MoveStateManager : NetworkBehaviour
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.CurTraction * Time.deltaTime);
//Need to have movecontroller involved for correct movement
if(currentState == CrouchState){
driftVel = Vector3.zero;
}
//Actually move he player
moveController.Move(driftVel);
}

View File

@@ -11,7 +11,7 @@ public class MoveCrouchState : MoveBaseState
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
//if not coming from slide state then rotate player and adjust height
if(previousState != mSM.SlideState){
if(previousState != mSM.SlideState && previousState != mSM.CrouchWalkState){
mSM.pStats.CurVel = 0;
mSM.moveController.height *= .5f;
mSM.moveController.center = new Vector3(0,mSM.moveController.center.y - mSM.moveController.height * .5f,0);
@@ -45,7 +45,9 @@ public class MoveCrouchState : MoveBaseState
Debug.Log(slideRay.collider.name);
}
}
else if((Input.GetAxis("Vertical") > 0.0f || Input.GetAxis("Horizontal") > 0.0f)){
mSM.SwitchState(mSM.CrouchWalkState);
}
//Debug.DrawRay(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up * 2f, Color.red);
@@ -58,8 +60,6 @@ public class MoveCrouchState : MoveBaseState
public override void FixedUpdateState(MoveStateManager mSM){
mSM.transform.Rotate(Vector3.up * -mSM.sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
mSM.SlideMovement();
mSM.CrouchMovement();
}
}

View File

@@ -9,32 +9,41 @@ public class MoveCrouchWalkState : MoveBaseState
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
//if next state isn't crouch revert rotation, speed, and height
if(nextState != mSM.CrouchState){
mSM.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
mSM.pStats.CurVel = mSM.calculatedCurVel;
mSM.moveController.height *= 2.0f;
mSM.moveController.center = new Vector3(0,mSM.moveController.center.y + mSM.moveController.height * .25f,0);
}
}
public override void UpdateState(MoveStateManager mSM){
if((!Input.GetKey(KeyCode.JoystickButton1) && !Input.GetKey(KeyCode.Q))){
mSM.SwitchState(mSM.CrouchState);
}
else if((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f)){
mSM.SwitchState(mSM.CrouchState);
}
//If falling stop sliding and go to wasd states
if(mSM.aSM.currentState == mSM.aSM.FallingState){
//Determine which state to go into based on player speed
if(mSM.calculatedCurVel < mSM.walkLimit){
mSM.SwitchState(mSM.WalkState);
}
else if(mSM.calculatedCurVel < mSM.runLimit){
mSM.SwitchState(mSM.JogState);
}
else{
mSM.SwitchState(mSM.RunState);
}
}
}
public override void FixedUpdateState(MoveStateManager mSM){
/*
if(mSM.aSM.currentState == mSM.aSM.FallingState){
//Determine which state to go into based on player speed
if(mSM.calculatedCurVel < mSM.walkLimit){
SlideToMoveState(mSM);
mSM.SwitchState(mSM.WalkState);
}
else if(mSM.calculatedCurVel < mSM.runLimit){
SlideToMoveState(mSM);
mSM.SwitchState(mSM.JogState);
}
else{
SlideToMoveState(mSM);
mSM.SwitchState(mSM.RunState);
}
}
*/
mSM.CrouchMovement();
}
}