Did some bugfixing and commented on everything

This commit is contained in:
Melbyj1125
2022-02-17 20:55:23 -06:00
parent e74a1c61c0
commit 820b11dd61
40 changed files with 528 additions and 250 deletions

View File

@@ -5,7 +5,7 @@ using UnityEngine;
public class MoveGrappleAirState : MoveBaseState
{
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
mSM.driftVel = Vector3.zero;
mSM.driftVel = Vector3.zero; // clears driftVel
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
@@ -13,6 +13,8 @@ public class MoveGrappleAirState : MoveBaseState
}
public override void UpdateState(MoveStateManager mSM){
//checks if aerial state manager is no longer air grappling
if(mSM.aSM.currentState != mSM.aSM.GrappleAirState){
//Determine which state to go into based on player speed
if(mSM.calculatedCurVel < mSM.walkLimit){
@@ -28,7 +30,8 @@ public class MoveGrappleAirState : MoveBaseState
}
public override void FixedUpdateState(MoveStateManager mSM){
//Directional movement to prevent weird movement issue
mSM.DirectionalMovement();
}
}

View File

@@ -4,42 +4,51 @@ using UnityEngine;
public class MoveRagdollState : MoveBaseState
{
float ragTime;
Vector3 prevRot;
bool beginRagTimer = false;
float ragTime; // ragdoll timer
Vector3 prevRot; // previous rotation before ragdolled
bool beginRagTimer = false; // whether ragtimer has started
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
ragTime = mSM.pStats.RecovTime;
prevRot = mSM.transform.localEulerAngles;
mSM.capCol.enabled = true;
mSM.moveController.enabled = false;
mSM.rB.isKinematic = false;
mSM.rB.detectCollisions = true;
ragTime = mSM.pStats.RecovTime; // how long to be ragdolled
prevRot = mSM.transform.localEulerAngles; // save previous rotation
mSM.capCol.enabled = true; // enable capsule collider
mSM.moveController.enabled = false; // disable move controller
mSM.rB.isKinematic = false; // disable kinematic
mSM.rB.detectCollisions = true; // detect collisions
//apply force
mSM.rB.AddForce(mSM.dirHit, ForceMode.Impulse);
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
mSM.pStats.GravVel = 50;
mSM.capCol.enabled = false;
mSM.moveController.enabled = true;
mSM.rB.isKinematic = true;
mSM.rB.detectCollisions = false;
mSM.transform.localEulerAngles = prevRot;
mSM.pStats.GravVel = 50; // resets gravVel
mSM.capCol.enabled = false; // disable capsule collider
mSM.moveController.enabled = true; // enable move controller
mSM.rB.isKinematic = true; // enable kinematic
mSM.rB.detectCollisions = false; // detect collisions false
mSM.transform.localEulerAngles = prevRot; // reset player rotation
}
public override void UpdateState(MoveStateManager mSM){
//if player hasn't touched the ground don't start timer
if(!beginRagTimer){
beginRagTimer = Physics.Raycast(mSM.transform.position, -Vector3.up, mSM.distToGround + 1f);
}
//start timer
else{
ragTime -= Time.deltaTime;
}
}
public override void FixedUpdateState(MoveStateManager mSM){
//Has to be in Fixed Update because it has player movement
//if ragtimer is over then recover
if(ragTime <= 0 && beginRagTimer){
ragTime = 0;
beginRagTimer = false;

View File

@@ -7,7 +7,7 @@ public class MoveRecoveringState : MoveBaseState
////// ADD SOMETHING THAT CHECKS ANIMATION FINISH BEFORE GO TO IDLE
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
mSM.CancelMomentum();
mSM.CancelMomentum(); // reset player variables
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
@@ -15,6 +15,8 @@ public class MoveRecoveringState : MoveBaseState
}
public override void UpdateState(MoveStateManager mSM){
//swap to idle state
mSM.SwitchState(mSM.IdleState);
}

View File

@@ -66,9 +66,9 @@ public class MoveStateManager : NetworkBehaviour
//Camera Variables
private Vector3 camRotation; // cameras camera rotation vector
[Range(-45, -15)]
public int minAngle = -30; // minimum downwards cam angle
public int minAngle = -18; // minimum downwards cam angle
[Range(30, 80)]
public int maxAngle = 45; // Max upwards cam angle
public int maxAngle = 30; // Max upwards cam angle
[Range(50, 500)]
public int sensitivity = 200; // Camera sensitivity
@@ -91,7 +91,7 @@ public class MoveStateManager : NetworkBehaviour
////Initialize Scripts
pStats = GetComponent<PlayerStats>(); // set PlayerStats
aSM = GetComponent<AerialStateManager>();
aSM = GetComponent<AerialStateManager>(); // aerial state manager
////
}
@@ -114,12 +114,17 @@ public class MoveStateManager : NetworkBehaviour
// Update is called once per frame
void Update()
{
//if (!IsLocalPlayer) { return; }
if (!IsLocalPlayer) { return; }
//calculates vel using driftVel will need to be relocated
calculatedCurVel = driftVel.magnitude * 50f;
GoToGrapple();
//if grappling in aerial state manager swap to grapple here
if(currentState != GrappleAirState){
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != RagdollState && currentState != RecoveringState)){
SwitchState(GrappleAirState);
}
}
//calls any logic in the update state from current state
currentState.UpdateState(this);
@@ -127,13 +132,14 @@ public class MoveStateManager : NetworkBehaviour
void FixedUpdate(){
//if (!IsLocalPlayer) { return; }
//calls any logic in the fixed update state from current state
currentState.FixedUpdateState(this);
if (!IsLocalPlayer) { return; }
//if camera is enabled then rotate
if(cam.enabled) Rotation();
else Debug.Log("Cam Disabled");
//calls any logic in the fixed update state from current state
currentState.FixedUpdateState(this);
}
public void SwitchState(MoveBaseState state){
@@ -194,6 +200,9 @@ public class MoveStateManager : NetworkBehaviour
vel = moveX + moveZ;
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.Traction * Time.deltaTime);
if(currentState == GrappleAirState){
driftVel = Vector3.zero;
}
//Actually move he player
moveController.Move(driftVel);
@@ -246,6 +255,7 @@ public class MoveStateManager : NetworkBehaviour
}
}
//Get hit into a ragdoll
public void GetHit(Vector3 dir, float force){
//if (!IsLocalPlayer) { return; }
dir.Normalize();
@@ -253,6 +263,7 @@ public class MoveStateManager : NetworkBehaviour
SwitchState(RagdollState);
}
//remove player momentum
public void CancelMomentum(){
pStats.CurVel = 0;
vel = Vector3.zero;
@@ -260,10 +271,6 @@ public class MoveStateManager : NetworkBehaviour
moveZ = Vector3.zero;
driftVel = Vector3.zero;
}
////
void GoToGrapple(){
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != RagdollState && currentState != RecoveringState)){
SwitchState(GrappleAirState);
}
}
}

View File

@@ -10,8 +10,8 @@ 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){
//Initialize Important Stats On state enter
mSM.pStats.CurVel = 0;
mSM.gameObject.transform.eulerAngles = new Vector3(mSM.transform.localEulerAngles.x - 90, mSM.transform.localEulerAngles.y, mSM.transform.localEulerAngles.z);
mSM.moveController.height *= .5f;
@@ -19,6 +19,8 @@ public class MoveCrouchState : MoveBaseState
}
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;

View File

@@ -10,7 +10,7 @@ public class MoveSlideState : MoveBaseState
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
//Initialize Important Stats On state enter
//Rotate player and adjust height and adjust traction
mSM.pStats.CurVel = 0;
originalTraction = mSM.pStats.Traction;
mSM.gameObject.transform.eulerAngles = new Vector3(mSM.transform.eulerAngles.x - 90, mSM.transform.eulerAngles.y, mSM.transform.eulerAngles.z);
@@ -19,12 +19,16 @@ public class MoveSlideState : MoveBaseState
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
//if next state isn't crouch then revert player rotation, height, and traction
if(nextState != mSM.CrouchState){
mSM.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
mSM.pStats.CurVel = mSM.calculatedCurVel;
mSM.pStats.Traction = originalTraction;
mSM.moveController.height *= 2.0f;
}
//if state is crouch revert traction
else{
mSM.pStats.Traction = originalTraction;
}
@@ -40,7 +44,11 @@ public class MoveSlideState : MoveBaseState
}
public override void FixedUpdateState(MoveStateManager mSM){
//counter rotates player so they don't rotate when camera is turned
mSM.transform.Rotate(Vector3.forward * -mSM.sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
//steadily increase traction
mSM.pStats.Traction += .004f;
///////ONCE WE HAVE IT SO SLIDE DOESNT ROTATE PLAYER MOVE THIS TO UPDATE
@@ -82,6 +90,8 @@ public class MoveSlideState : MoveBaseState
}
}
*/
//actual slide movement
mSM.SlideMovement();
}
}

View File

@@ -20,12 +20,14 @@ public class MoveIdleState : MoveBaseState
}
//If Q or joystick button1 crouch state
if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
mSM.SwitchState(mSM.CrouchState);
}
}
public override void FixedUpdateState(MoveStateManager mSM){
//actual directional movement
mSM.DirectionalMovement();
}
}

View File

@@ -24,12 +24,14 @@ public class MoveJogState : MoveBaseState
}
//move to slide if Q or JoystickButton1
if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
mSM.SwitchState(mSM.SlideState);
}
}
public override void FixedUpdateState(MoveStateManager mSM){
//actual directional movment
mSM.DirectionalMovement();
}
}

View File

@@ -20,12 +20,13 @@ public class MoveRunState : MoveBaseState
}
//move to slide if Q or JoystickButton1
if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
mSM.SwitchState(mSM.SlideState);
}
}
public override void FixedUpdateState(MoveStateManager mSM){
//actual direction movement
mSM.DirectionalMovement();
}
}

View File

@@ -24,12 +24,13 @@ public class MoveWalkState : MoveBaseState
}
//move to slide if Q or JoystickButton1
if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
mSM.SwitchState(mSM.SlideState);
}
}
public override void FixedUpdateState(MoveStateManager mSM){
//actual directional movemnt
mSM.DirectionalMovement();
}
}