diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs index d231722..91f04d0 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugAerialState/dAerialStateManager.cs @@ -247,8 +247,6 @@ public class dAerialStateManager : 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("The grounds Normal" + groundHit.normal); moveController.Move(groundHit.normal * 20 * Time.deltaTime); mSM.CancelMomentum(); } diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchState.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchState.cs index ea3ad2b..2ffd4ec 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchState.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchState.cs @@ -11,7 +11,7 @@ public class dMoveCrouchState : dMoveBaseState public override void EnterState(dMoveStateManager mSM, dMoveBaseState 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,6 +45,9 @@ public class dMoveCrouchState : dMoveBaseState 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 +61,6 @@ public class dMoveCrouchState : dMoveBaseState public override void FixedUpdateState(dMoveStateManager mSM){ - mSM.transform.Rotate(Vector3.up * -mSM.sensitivity * Time.deltaTime * Input.GetAxis("Mouse X")); - - mSM.SlideMovement(); + mSM.CrouchMovement(); } } diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchWalkState.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchWalkState.cs index fc94b2f..56282b8 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchWalkState.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveCrouchWalkState.cs @@ -9,32 +9,41 @@ public class dMoveCrouchWalkState : dMoveBaseState } public override void ExitState(dMoveStateManager mSM, dMoveBaseState 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(dMoveStateManager 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(dMoveStateManager 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(); } } diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveSlideState.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveSlideState.cs index a46c0ca..8985a62 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveSlideState.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/DebugSlide/dMoveSlideState.cs @@ -32,6 +32,7 @@ public class dMoveSlideState : dMoveBaseState //if state is crouch revert traction else{ mSM.pStats.CurTraction = mSM.pStats.Traction; + mSM.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0); } mSM.GetComponent().SetBool("isSliding", false); } diff --git a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/dMoveStateManager.cs b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/dMoveStateManager.cs index d0942b9..591094d 100644 --- a/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/dMoveStateManager.cs +++ b/Assets/Scripts/PlayerScripts/DebugStateMachine/DebugMoveState/dMoveStateManager.cs @@ -211,6 +211,40 @@ public class dMoveStateManager : 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 @@ -262,11 +296,6 @@ public class dMoveStateManager : NetworkBehaviour vel = moveX + moveZ; Vector3 moveXZ = new Vector3(vel.x, 0, vel.z); driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.CurTraction * Time.deltaTime); - - //need to have move controller involved for correct movement - if(currentState == CrouchState){ - driftVel = Vector3.zero; - } //Actually move he player moveController.Move(driftVel); @@ -320,11 +349,6 @@ public class dMoveStateManager : NetworkBehaviour driftVel = Vector3.zero; } - //Verify Movement - private void VerifyMovement(){ - - } - //Apply Wind movement to the player public void ApplyWind(bool wind){ if(wind){ diff --git a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs index 1c0654b..fe915fc 100644 --- a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs +++ b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/AerialState/AerialStateManager.cs @@ -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(); diff --git a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/MoveStateManager.cs b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/MoveStateManager.cs index 3b1e372..c118f1c 100644 --- a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/MoveStateManager.cs +++ b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/MoveStateManager.cs @@ -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); } diff --git a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchState.cs b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchState.cs index 83185f9..be1a873 100644 --- a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchState.cs +++ b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchState.cs @@ -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(); } } diff --git a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchWalkState.cs b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchWalkState.cs index c9874b9..524e2f0 100644 --- a/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchWalkState.cs +++ b/Assets/Scripts/PlayerScripts/NetworkedStateMachines/MovementState/Slide/MoveCrouchWalkState.cs @@ -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(); } }