mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 01:44:30 -05:00
Implemented Crouch walking
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Animator>().SetBool("isSliding", false);
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user