reworked grapple functionally more of a hookshot

This commit is contained in:
Melbyj1125
2022-04-03 21:40:12 -05:00
parent 15acf40031
commit bbcd239d12
37 changed files with 153 additions and 423 deletions

View File

@@ -7,17 +7,26 @@ public class dAerialGrappleAirState : dAerialBaseState
Vector3 initialForceDirection;
float distanceBeneathHook = 4f;
float distanceAfterHook = 5f;
float distanceBeneathHook = -3f;
float distanceAfterHook = 8f;
Vector3 desiredPosition;
bool pointReached = false;
float initialForcePower = 4;
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
distanceBeneathHook = -3f;
distanceAfterHook = 8f;
pointReached = false;
initialForcePower = 4;
//refresh jump number
aSM.curJumpNum = 0;
aSM.release = false;
Vector3 updatedYHookPoint = new Vector3(aSM.hookPoint.transform.position.x, aSM.hookPoint.transform.position.y - distanceBeneathHook, aSM.hookPoint.transform.position.z);
Vector3 updatedXHookPointDirection = (new Vector3(aSM.transform.position.x, 0, aSM.transform.position.z) - new Vector3(aSM.hookPoint.transform.position.x, 0, aSM.hookPoint.transform.position.z)).normalized;
@@ -27,16 +36,35 @@ public class dAerialGrappleAirState : dAerialBaseState
initialForceDirection = desiredPosition - aSM.transform.position;
initialForceDirection = initialForceDirection.normalized;
aSM.postForceDirection = new Vector3(initialForceDirection.x, 0, initialForceDirection.z).normalized;
aSM.currentForcePower = initialForcePower;
}
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
if(nextState == aSM.GroundedState || nextState == aSM.WallRunState){
aSM.release = false;
}
else{
aSM.release = true;
aSM.pStats.GravVel = 10;
}
}
public override void UpdateState(dAerialStateManager aSM){
if(pointReached){
//if grounded at when the point is reached then goto grounded state
if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
else if(!aSM.isGrounded){
aSM.SwitchState(aSM.FallingState);
}
//if wallrunning then wallrun
else if(aSM.isWallRunning){
aSM.SwitchState(aSM.WallRunState);
}
}
}
public override void FixedUpdateState(dAerialStateManager aSM){
@@ -45,23 +73,26 @@ public class dAerialGrappleAirState : dAerialBaseState
//Draw Line between player and hookpoint for debug purposes
Debug.DrawRay(aSM.transform.position, initialForceDirection); //Visual of line
Vector3 tempForceDir = desiredPosition - aSM.transform.position;
tempForceDir = tempForceDir.normalized;
tempForceDir = new Vector3(tempForceDir.x,0,tempForceDir.z).normalized;
if((aSM.postForceDirection - tempForceDir).magnitude >= .1f && !pointReached){
pointReached = true;
}
//Apply default gravity
if(!pointReached){
aSM.moveController.Move(initialForceDirection * .1f);
aSM.GravityCalculation(.1f);
aSM.moveController.Move(initialForceDirection * initialForcePower);
aSM.GravityCalculation(0);
aSM.pStats.GravVel = 0;
}
else{
//currentForcePower;
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
}
float CalculateInitialForcePower(){
return 0;
}
float ForceDissipation(){
return 0;
}
}

View File

@@ -1,46 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class dAerialGrappleGroundedState : dAerialBaseState
{
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
aSM.release = false; // release is false when grounded
}
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
}
public override void UpdateState(dAerialStateManager aSM){
//if E is pressed or ragdolling then grounded
if(((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld && !aSM.pStats.IsPaused) || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
aSM.SwitchState(aSM.GroundedState);
}
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2)) && aSM.eHeld){
aSM.eHeld = false;
}
//if not grounded and gravVel < 0 then grapple air
else if(!aSM.isGrounded && aSM.pStats.GravVel < 0){
aSM.SwitchState(aSM.GrappleAirState);
}
//if distance between player and hookpoint is too far then grounded
else if(Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position) > aSM.maxGrappleDistance){
aSM.SwitchState(aSM.GroundedState);
}
}
public override void FixedUpdateState(dAerialStateManager aSM){
Debug.DrawRay(aSM.transform.position, (aSM.hookPoint.transform.position - aSM.transform.position)); //Visual of line
//Default gravity calculation
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
}

View File

@@ -22,7 +22,6 @@ public class dAerialStateManager : NetworkBehaviour
public dAerialWallIdleState WallIdleState = new dAerialWallIdleState();
//Grappling States
public dAerialGrappleGroundedState GrappleGroundedState = new dAerialGrappleGroundedState();
public dAerialGrappleAirState GrappleAirState = new dAerialGrappleAirState();
////
@@ -90,12 +89,9 @@ public class dAerialStateManager : NetworkBehaviour
public GameObject[] hookPoints; // Hook point list
public int hookPointIndex; // Hook point Index
public float distance; // distance of hookpoints
public float maxGrappleDistance = 25; // Max Rope Length
public bool release = false; // has player ungrappled
public Vector3 tempRelease; // temporary release force vector
public Vector3 lerpRelease; // lerped release force vector
public Vector3 forceDirection; // force direction vector
public bool eHeld; // is e being held
public Vector3 postForceDirection; // force direction vector
public float currentForcePower = 0;
////
void Awake(){
@@ -252,9 +248,7 @@ public class dAerialStateManager : NetworkBehaviour
//Actually applies the downwards movement
void DownwardMovement(){
Vector3 moveY = new Vector3(0,pStats.GravVel,0) * Time.deltaTime;
moveController.Move(moveY);
}
//applies Jump values and Variables
@@ -472,11 +466,12 @@ public class dAerialStateManager : NetworkBehaviour
if(!pStats.IsPaused){
if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && pStats.HasGrapple) //If grapple button is hit
{
Debug.Log("Checking Hooks");
hookPointIndex = FindHookPoint(); //Find the nearest hook point within max distance
if (hookPointIndex != -1) //If there is a hookpoint
{
Debug.Log("Found Hook");
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
eHeld = true;
return true;
}
}
@@ -503,9 +498,10 @@ public class dAerialStateManager : NetworkBehaviour
//lerped grapple release force and dissipation of it
public void GrappleReleaseForce(){
if(release){
lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 9f * Time.deltaTime);
tempRelease *= .98f;
moveController.Move(lerpRelease);
currentForcePower *= .90f;
moveController.Move(postForceDirection * currentForcePower);
if(currentForcePower < .05) release = false;
}
}
////

View File

@@ -22,7 +22,7 @@ public class dMoveIdleState : dMoveBaseState
}
//If Q or joystick button1 crouch state
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.pStats.IsPaused){
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.pStats.IsPaused){
mSM.SwitchState(mSM.CrouchState);
}
}

View File

@@ -26,7 +26,7 @@ public class dMoveJogState : dMoveBaseState
}
//move to slide if Q or JoystickButton1
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.pStats.IsPaused){
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.pStats.IsPaused){
mSM.SwitchState(mSM.SlideState);
}
}

View File

@@ -22,7 +22,7 @@ public class dMoveRunState : dMoveBaseState
}
//move to slide if Q or JoystickButton1
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.pStats.IsPaused){
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.pStats.IsPaused){
mSM.SwitchState(mSM.SlideState);
}
}

View File

@@ -29,7 +29,7 @@ public class dMoveWalkState : dMoveBaseState
}
//move to slide if Q or JoystickButton1
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.pStats.IsPaused){
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.pStats.IsPaused){
mSM.SwitchState(mSM.SlideState);
}
}

View File

@@ -28,7 +28,7 @@ public class dOffenseAirKickState : dOffenseBaseState
public override void UpdateState(dOffenseStateManager oSM){
//if incapacitated then cooldown
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState)){
oSM.SwitchState(oSM.CooldownState);
}

View File

@@ -29,7 +29,7 @@ public class dOffenseKickState : dOffenseBaseState
public override void UpdateState(dOffenseStateManager oSM){
//if incapacitated then cooldown
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState)){
oSM.SwitchState(oSM.CooldownState);
}

View File

@@ -20,7 +20,7 @@ public class dOffenseCooldownState : dOffenseBaseState
public override void UpdateState(dOffenseStateManager oSM){
//if cooldown over and incapacitated then incapacitated
if(cooldown && (oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
if(cooldown && (oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState)){
oSM.SwitchState(oSM.IncapacitatedState);
}

View File

@@ -15,7 +15,7 @@ public class dOffenseIncapacitatedState : dOffenseBaseState
public override void UpdateState(dOffenseStateManager oSM){
//if no longer incapacitated then None
if((oSM.mSM.currentState != oSM.mSM.RagdollState && oSM.mSM.currentState != oSM.mSM.SlideState && oSM.mSM.currentState != oSM.mSM.CrouchState && oSM.mSM.currentState != oSM.mSM.CrouchWalkState) && (oSM.aSM.currentState != oSM.aSM.WallRunState && oSM.aSM.currentState != oSM.aSM.WallIdleState && oSM.aSM.currentState != oSM.aSM.GrappleAirState && oSM.aSM.currentState != oSM.aSM.GrappleGroundedState)){
if((oSM.mSM.currentState != oSM.mSM.RagdollState && oSM.mSM.currentState != oSM.mSM.SlideState && oSM.mSM.currentState != oSM.mSM.CrouchState && oSM.mSM.currentState != oSM.mSM.CrouchWalkState) && (oSM.aSM.currentState != oSM.aSM.WallRunState && oSM.aSM.currentState != oSM.aSM.WallIdleState && oSM.aSM.currentState != oSM.aSM.GrappleAirState)){
oSM.SwitchState(oSM.NoneState);
}
}

View File

@@ -15,7 +15,7 @@ public class dOffenseNoneState : dOffenseBaseState
public override void UpdateState(dOffenseStateManager oSM){
//if incapacitated then incapacitated
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState)){
oSM.SwitchState(oSM.IncapacitatedState);
}