mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-03-22 09:44:15 -05:00
67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MoveCrouchState : MoveBaseState
|
|
{
|
|
|
|
//Slide Variables
|
|
RaycastHit slideRay; // slide raycast
|
|
|
|
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
|
|
|
|
//if not coming from slide state then rotate player and adjust height
|
|
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);
|
|
//mSM.moveController.Move(new Vector3(0,-mSM.moveController.height * .5f,0));
|
|
}
|
|
mSM.animator.SetBool("isCrouching", true);
|
|
}
|
|
|
|
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
|
|
|
|
//if next state isn't crouch walk revert rotation, speed, and height
|
|
if(nextState != mSM.CrouchWalkState){
|
|
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);
|
|
}
|
|
mSM.animator.SetBool("isCrouching", false);
|
|
}
|
|
|
|
public override void UpdateState(MoveStateManager mSM){
|
|
|
|
//If player isn't pressing either Q or the joystick button they stop crouching if nothing is above them
|
|
if((!Input.GetKey(KeyCode.JoystickButton1) && !Input.GetKey(GameManager.GM.bindableActions["slideKey"]))){
|
|
|
|
if ((Physics.Raycast(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up, out slideRay, 2f, mSM.layerMask) == false)){
|
|
|
|
mSM.SwitchState(mSM.IdleState);
|
|
}
|
|
else{
|
|
|
|
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);
|
|
|
|
|
|
//If falling stop sliding and go to wasd states
|
|
if(mSM.aSM.currentState == mSM.aSM.FallingState){
|
|
mSM.SwitchState(mSM.IdleState);
|
|
}
|
|
|
|
}
|
|
|
|
public override void FixedUpdateState(MoveStateManager mSM){
|
|
|
|
mSM.CrouchMovement();
|
|
}
|
|
}
|