lose Mom on wall and kick renetworked

This commit is contained in:
Melbyj1125
2022-02-23 13:55:30 -06:00
parent b9a573a97d
commit d9629ec555
8 changed files with 92 additions and 30 deletions

View File

@@ -7,7 +7,6 @@ public class dMoveCrouchState : dMoveBaseState
//Slide Variables
RaycastHit slideRay; // slide raycast
int layerMask;
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
@@ -17,8 +16,6 @@ public class dMoveCrouchState : dMoveBaseState
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));
layerMask = 1 << 3;
layerMask = ~layerMask;
}
}
@@ -39,7 +36,7 @@ public class dMoveCrouchState : dMoveBaseState
//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(KeyCode.Q))){
if ((Physics.Raycast(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up, out slideRay, 2f, layerMask) == false)){
if ((Physics.Raycast(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up, out slideRay, 2f, mSM.layerMask) == false)){
mSM.SwitchState(mSM.IdleState);
}

View File

@@ -7,7 +7,6 @@ public class dMoveSlideState : dMoveBaseState
//Slide Variables
float originalTraction; // Traction before slide started
RaycastHit slideRay; // slide raycast
int layerMask;
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
@@ -18,8 +17,6 @@ public class dMoveSlideState : dMoveBaseState
mSM.pStats.Traction = 0.01f;
mSM.moveController.center = new Vector3(0,mSM.moveController.center.y - mSM.moveController.height * .5f,0);
//mSM.moveController.Move(new Vector3(0,-0.1f,0));
layerMask = 1 << 3;
layerMask = ~layerMask;
}
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
@@ -51,7 +48,7 @@ public class dMoveSlideState : dMoveBaseState
//If player isn't pressing either Q or the joystick button they stop sliding if nothing is above them
if((!Input.GetKey(KeyCode.JoystickButton1) && !Input.GetKey(KeyCode.Q))){
if ((Physics.Raycast(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up, out slideRay, 2f, layerMask) == false)){
if ((Physics.Raycast(mSM.gameObject.transform.position + new Vector3(0,1f,0), Vector3.up, out slideRay, 2f, mSM.layerMask) == false)){
//Determine which state to go into based on player speed
if(mSM.calculatedCurVel < mSM.walkLimit){

View File

@@ -59,6 +59,10 @@ public class dMoveStateManager : NetworkBehaviour
private Vector3 moveX; // Local Vertical Vector
public Vector3 driftVel; // Lerped Movement Vector
public float calculatedCurVel; // calculated current vel using driftVel
public int layerMask; // LayerMask to exclude player
RaycastHit wallHitTop, wallHitBot; // Raycast for momentum loss on wall hit
private Vector3 lastVel; // previous vel
private bool firstWallHit = false; // hit the wall for the first time
//Camera Variables
private Vector3 camRotation; // cameras camera rotation vector
@@ -90,6 +94,12 @@ public class dMoveStateManager : NetworkBehaviour
pStats = GetComponent<PlayerStats>(); // set PlayerStats
aSM = GetComponent<dAerialStateManager>(); // aerial state manager
////
////Initialize Variables
layerMask = 1 << 3;
layerMask = ~layerMask;
////
}
// Start is called before the first frame update
@@ -102,6 +112,7 @@ public class dMoveStateManager : NetworkBehaviour
//Slide Upwards Variable
distToGround = GetComponent<Collider>().bounds.extents.y; // set players distance to ground
lastVel = Vector3.zero;
//if (!IsLocalPlayer) { return; }
Cursor.lockState = CursorLockMode.Locked; // Lock cursor on start if you are the local player
@@ -117,7 +128,7 @@ public class dMoveStateManager : NetworkBehaviour
//if grappling in aerial state manager swap to grapple here
if(currentState != GrappleAirState){
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != RagdollState && currentState != RecoveringState)){
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != CrouchState && currentState != RagdollState && currentState != RecoveringState)){
SwitchState(GrappleAirState);
}
}
@@ -161,7 +172,7 @@ public class dMoveStateManager : NetworkBehaviour
return pStats.CurVel;
}
//If current speed is below min when pressed set to minimum speed
else if (pStats.CurVel < pStats.MinVel)
else if (pStats.CurVel < pStats.MinVel || firstWallHit == true)
{
pStats.CurVel = pStats.MinVel;
return pStats.MinVel;
@@ -192,9 +203,24 @@ public class dMoveStateManager : NetworkBehaviour
//Checks if movement keys have been pressed and calculates correct vector
moveX = transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * PlayerSpeed();
moveZ = transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * PlayerSpeed();
vel = moveX + moveZ;
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
//Raycast offset
Vector3 rayOffset = moveXZ - lastVel;
//Check if wall is in direction player is moving
if (((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, moveXZ.normalized, out wallHitBot, .2f, layerMask) == true) || ((currentState != SlideState || currentState != CrouchState) && (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), moveXZ.normalized, out wallHitTop, .5f, layerMask) == true))) && !firstWallHit){
CancelMomentum();
firstWallHit = true;
}
else if((Physics.Raycast(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, moveXZ.normalized, out wallHitBot, .2f, layerMask) == false) || ((currentState != SlideState || currentState != CrouchState) && (Physics.Raycast(gameObject.transform.position + new Vector3(0,2.2f,0), moveXZ.normalized, out wallHitTop, .5f, layerMask) == false))){
firstWallHit = false;
}
Debug.DrawRay(gameObject.transform.position + new Vector3(0,.4f,0) + rayOffset, moveXZ.normalized * 1f, Color.red);
Debug.DrawRay(gameObject.transform.position + new Vector3(0,2.2f,0) + rayOffset, moveXZ.normalized * 1f, Color.red);
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.Traction * Time.deltaTime);
if(currentState == GrappleAirState){
driftVel = Vector3.zero;