mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 18:04:27 -05:00
Did some bugfixing and commented on everything
This commit is contained in:
@@ -15,26 +15,27 @@ public class AerialFallingState : AerialBaseState
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
|
||||
//if Grav Vel > 0 then jumping
|
||||
if(aSM.pStats.GravVel > 0){
|
||||
if(aSM.pStats.GravVel > 0 && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.JumpingState);
|
||||
}
|
||||
|
||||
//if jump has been pressed and has glider and is in a state that allows it glide
|
||||
else if(Input.GetButton("Jump") && aSM.pStats.HasGlider && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.GlidingState);
|
||||
}
|
||||
|
||||
//if is grounded then grounded
|
||||
if(aSM.isGrounded){
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if is wallrunning ands is in a state that allows it wallrun
|
||||
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
//if grapple is possible and in state that allows it grapple air
|
||||
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,22 +22,22 @@ public class AerialGlidingState : AerialBaseState
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
|
||||
//if not holding jump fall
|
||||
if(!Input.GetButton("Jump")){
|
||||
if(!Input.GetButton("Jump") || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
|
||||
//if is grounded then grounded
|
||||
if(aSM.isGrounded){
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if isWallrunning and in state that allows it wallrun
|
||||
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
//if can grapple and in state that allows it grapple
|
||||
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@ public class AerialGroundedState : AerialBaseState
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
|
||||
//if grav vel < 0 then falling
|
||||
if(aSM.pStats.GravVel < 0){
|
||||
if(aSM.pStats.GravVel < 0 || (aSM.pStats.GravVel > 0 && (aSM.mSM.currentState == aSM.mSM.SlideState || aSM.mSM.currentState == aSM.mSM.RagdollState || aSM.mSM.currentState == aSM.mSM.RecoveringState))){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
//if grav vel > 0 then jumping
|
||||
else if(aSM.pStats.GravVel > 0){
|
||||
else if(aSM.pStats.GravVel > 0 && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.JumpingState);
|
||||
}
|
||||
|
||||
//can grapple and in state that allows grapple
|
||||
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
aSM.SwitchState(aSM.GrappleGroundedState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,22 @@ public class AerialJumpingState : AerialBaseState
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
|
||||
//if grav vel < 0 falling
|
||||
if(aSM.pStats.GravVel < 0){
|
||||
if(aSM.pStats.GravVel < 0 || aSM.mSM.currentState == aSM.mSM.RagdollState){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
|
||||
//if is grounded then grounded
|
||||
if(aSM.isGrounded){
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if is wall running and in a state that allows it wallrun
|
||||
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
//if can grapple and in a state that allows it grapple
|
||||
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@ public class AerialStateManager : NetworkBehaviour
|
||||
|
||||
////Objects Sections
|
||||
GameObject parentObj; // Parent object
|
||||
public Camera cam; // Camera object
|
||||
////
|
||||
|
||||
////Components Section
|
||||
public CharacterController moveController; // Character Controller
|
||||
Rigidbody rB; // Players Rigidbody
|
||||
CapsuleCollider capCol; // Players Capsule Collider
|
||||
Animator animator; // Animation Controller
|
||||
////
|
||||
|
||||
@@ -65,43 +63,42 @@ public class AerialStateManager : NetworkBehaviour
|
||||
RaycastHit groundHit; // ground raycast
|
||||
|
||||
//Wallrun
|
||||
float wallMaxDistance = 3f;
|
||||
float wallSpeedMultiplier = 1.5f;
|
||||
float minimumHeight = .1f;
|
||||
float wallMaxDistance = 3f; // distance to wall that player can attach from
|
||||
float minimumHeight = .1f; // minimum height player has to be
|
||||
[Range(0.0f, 1.0f)]
|
||||
float normalizedAngleThreshold = 0.1f;
|
||||
float jumpDuration = .02f;
|
||||
float wallBouncing = 3;
|
||||
Vector3[] directions;
|
||||
RaycastHit[] hits;
|
||||
public bool isWallRunning = false;
|
||||
Vector3 lastWallPosition;
|
||||
Vector3 lastWallNormal;
|
||||
float elapsedTimeSinceJump = 0;
|
||||
float elapsedTimeSinceWallAttach = 0;
|
||||
float elapsedTimeSinceWallDetatch = 0;
|
||||
bool jumping;
|
||||
float normalizedAngleThreshold = 0.1f; // angle player can attach to wall from
|
||||
float jumpDuration = .02f; // jump duration
|
||||
float wallBouncing = 3; // wall bouncing
|
||||
Vector3[] directions; // cardinal direction to attach to wall
|
||||
RaycastHit[] hits; // where we hit wall
|
||||
public bool isWallRunning = false; // if player is wallrunning
|
||||
Vector3 lastWallPosition; // last wall position
|
||||
Vector3 lastWallNormal; // last wall normal
|
||||
float elapsedTimeSinceJump = 0; // time since jump
|
||||
float elapsedTimeSinceWallAttach = 0; // time since attached to wall
|
||||
float elapsedTimeSinceWallDetatch = 0; // time since detached
|
||||
bool jumping; // is player jumping
|
||||
|
||||
//Impact Variables
|
||||
float mass = 5.0F; // mass variable for Impact
|
||||
Vector3 impact = Vector3.zero; // Impact Vector
|
||||
|
||||
//Grapple Variables
|
||||
public float maxGrabDistance = 30;// Max Distance can cast grapple
|
||||
public float maxGrabDistance = 50;// Max Distance can cast grapple
|
||||
public GameObject hookPoint; // Actual Hook points
|
||||
public GameObject[] hookPoints; // Hook point list
|
||||
public int hookPointIndex; // Hook point Index
|
||||
public float distance; // distance of hookpoints
|
||||
public float maxGrappleDistance = 20; // Max Rope Length
|
||||
public float maxSwingSpeed = 50;
|
||||
public float minSwingSpeed = 20;
|
||||
public float swingAcc = 3f;
|
||||
public float maxSwingMom = 60;
|
||||
public bool release = false;
|
||||
public Vector3 tempRelease;
|
||||
public Vector3 lerpRelease;
|
||||
public Vector3 forceDirection;
|
||||
public bool eHeld;
|
||||
public float maxGrappleDistance = 25; // Max Rope Length
|
||||
public float maxSwingSpeed = 50; // max swing speed
|
||||
public float minSwingSpeed = 20; // min swing speed
|
||||
public float swingAcc = 3f; // swing acceleration
|
||||
public float maxSwingMom = 60; // max swing momentum
|
||||
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
|
||||
////
|
||||
|
||||
void Awake(){
|
||||
@@ -109,8 +106,6 @@ public class AerialStateManager : NetworkBehaviour
|
||||
////Initialize Player Components
|
||||
moveController = GetComponent<CharacterController>(); // set Character Controller
|
||||
rB = GetComponent<Rigidbody>(); //set Rigid Body
|
||||
capCol = GetComponent<CapsuleCollider>(); // set Capsule Collider
|
||||
capCol.enabled = true;
|
||||
parentObj = transform.parent.gameObject; // set parent object
|
||||
animator = GetComponent<Animator>(); // set animator
|
||||
////
|
||||
@@ -156,11 +151,20 @@ public class AerialStateManager : NetworkBehaviour
|
||||
|
||||
//calls any logic in the fixed update state from current state
|
||||
currentState.FixedUpdateState(this);
|
||||
|
||||
//Some functions that need to be active if move controller is active
|
||||
if(moveController.enabled){
|
||||
|
||||
//Allows player to jump
|
||||
Jump();
|
||||
|
||||
//checks ground
|
||||
GroundCheck();
|
||||
|
||||
//Applies downwards movement
|
||||
DownwardMovement();
|
||||
|
||||
//if player has wallrun then do wall run routine
|
||||
if(pStats.HasWallrun){
|
||||
WallRunRoutine();
|
||||
}
|
||||
@@ -168,7 +172,9 @@ public class AerialStateManager : NetworkBehaviour
|
||||
//Dissipates Impact
|
||||
DissipateImpact();
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
//Gravity without moveController
|
||||
pStats.GravVel -= pStats.PlayerGrav * Time.deltaTime;
|
||||
rB.AddForce(new Vector3(0,pStats.GravVel,0));
|
||||
@@ -499,6 +505,7 @@ public class AerialStateManager : NetworkBehaviour
|
||||
return index;
|
||||
}
|
||||
|
||||
//lerped grapple release force and dissipation of it
|
||||
public void GrappleReleaseForce(){
|
||||
if(release){
|
||||
lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 9f * Time.deltaTime);
|
||||
|
||||
@@ -4,21 +4,24 @@ using UnityEngine;
|
||||
|
||||
public class AerialGrappleAirState : AerialBaseState
|
||||
{
|
||||
|
||||
bool spaceHeld = true;
|
||||
float ropeLength; // current rope length
|
||||
Vector3 swingDirection; // Swing direction
|
||||
float inclinationAngle; // inclination angle
|
||||
float theta = -1; // theta
|
||||
float swingMom;
|
||||
Vector3 tensionMomDirection;
|
||||
Vector3 hookPointRight;
|
||||
Vector3 momDirection;
|
||||
Vector3 curXZDir;
|
||||
Vector3 oldXZDir;
|
||||
float swingSpeed = 10;
|
||||
bool swingback = false; //swing the player back
|
||||
float oldSwingMom;
|
||||
Vector3 tensionDirection;
|
||||
float tensionForce;
|
||||
float theta = -1; // theta for rope angle
|
||||
Vector3 hookPointRight; // right vector of the hook point
|
||||
Vector3 curXZDir; // current straight line between player and hook point ignoring y axis
|
||||
Vector3 oldXZDir; // old straight line between player and hook point ignoring y axis
|
||||
|
||||
Vector3 swingDirection; // Swing direction
|
||||
float swingSpeed = 10; // cur swing speed
|
||||
Vector3 tensionDirection; // tension direction
|
||||
float tensionForce; // tension force amplifier
|
||||
|
||||
float swingMom; // swing Mom amplifier
|
||||
float oldSwingMom; // old swing Momentum amplifier
|
||||
Vector3 momDirection; // momentum direction
|
||||
Vector3 tensionMomDirection; // tension momentum direction
|
||||
|
||||
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
|
||||
|
||||
@@ -43,48 +46,61 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
aSM.pStats.GravVel = -1; // grav vel is adjusted so things work
|
||||
aSM.release = false; // player hasn't released
|
||||
aSM.lerpRelease = Vector3.zero; // reset lerp release
|
||||
spaceHeld = true;
|
||||
}
|
||||
|
||||
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
|
||||
|
||||
//If not going into grapple grounded state
|
||||
if(nextState != aSM.GrappleGroundedState){
|
||||
aSM.release = true;
|
||||
aSM.pStats.GravVel = 0;
|
||||
aSM.forceDirection = Vector3.zero;
|
||||
swingback = true;
|
||||
}
|
||||
|
||||
//If going into grapple grounded state
|
||||
else{
|
||||
aSM.pStats.GravVel = 0;
|
||||
aSM.forceDirection = Vector3.zero;
|
||||
swingback = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
|
||||
if((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld){
|
||||
|
||||
//if pressing E or ragdolling then falling
|
||||
if(((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld) || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2))){
|
||||
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2)) && aSM.eHeld){
|
||||
aSM.eHeld = false;
|
||||
}
|
||||
|
||||
if(Input.GetButton("Jump")){
|
||||
|
||||
//if pressing Jump then jump
|
||||
else if(Input.GetButton("Jump") && !spaceHeld){
|
||||
aSM.SwitchState(aSM.JumpingState);
|
||||
}
|
||||
else if(!(Input.GetButton("Jump")) && spaceHeld){
|
||||
spaceHeld = false;
|
||||
}
|
||||
|
||||
if(aSM.isGrounded){
|
||||
//if grounded then grapple grounded
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GrappleGroundedState);
|
||||
}
|
||||
|
||||
//if wallrunning then wallrun
|
||||
else if(aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(AerialStateManager aSM){
|
||||
|
||||
|
||||
////////ADD A LINE RENDERER WHEN WE GET THE HAND MODEL
|
||||
//Draw Line between player and hookpoint for debug purposes
|
||||
Debug.DrawRay(aSM.transform.position, (aSM.hookPoint.transform.position - aSM.transform.position)); //Visual of line
|
||||
|
||||
//Debug.Log(Vector3.Distance(gameObject.transform.position, hookPoint.transform.position));
|
||||
//Calculate tether force direction based on hookpoint
|
||||
if (Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position) >= ropeLength )
|
||||
{
|
||||
@@ -94,26 +110,23 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
aSM.forceDirection = Vector3.zero;
|
||||
}
|
||||
|
||||
//Move player based on their inputs
|
||||
aSM.moveController.Move(SwingMoveController(aSM));
|
||||
|
||||
//if Swing Momentum isn't zero then move player
|
||||
if(swingMom != 0){
|
||||
aSM.moveController.Move(CalculateMomentumDirection(aSM.pStats.GravVel, aSM.hookPoint.transform.position, aSM));
|
||||
swingMom -= .5f;
|
||||
}
|
||||
|
||||
if(swingMom<0) swingMom = 0;
|
||||
|
||||
//Calculate temp release at every position
|
||||
aSM.tempRelease = CalculateSwingReleaseForce();
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
}
|
||||
|
||||
//Needs to be Overhauled to properly implement energy loss taking into account players current Velocity, height and input
|
||||
//------Important Equations--------
|
||||
// TensionForce = Cos(theta) * g * m * Vector3(tensionDirection)
|
||||
// Potential Energy = m * g * h -- Will need to modify adding current speed
|
||||
// Kinetic Energy = 1/2 * m * V^2 -- assuming no energy loss at the bottom KE = PE at peak we will add energy loss ourselves
|
||||
// Total Energy = m * ((g*h) + (1/2 * V^2))
|
||||
// Velocity = (2 * ((TotalEnergy/m) - (g*h)))^(1/2) -- This hypothetically could be used for our swing momentum calculation
|
||||
// Movement Direction right angle of tension force = Sin(theta) * g * m * Vector3(Right angle to tensionDirection)
|
||||
//Apply default gravity
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
|
||||
}
|
||||
|
||||
//Calculate the tether direction vector and how much force that vector needs
|
||||
Vector3 CalculateForceDirection(float mass, float g, Vector3 hPoint, AerialStateManager aSM){
|
||||
@@ -129,7 +142,10 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
|
||||
//force direction calculation based on tension direction and force
|
||||
Vector3 fDirection = tensionDirection * tensionForce;
|
||||
|
||||
//return force direction
|
||||
return fDirection;
|
||||
|
||||
}
|
||||
|
||||
Vector3 CalculateMomentumDirection(float g, Vector3 hPoint, AerialStateManager aSM){
|
||||
@@ -137,23 +153,20 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
tensionMomDirection = (hPoint - aSM.transform.position).normalized;
|
||||
hookPointRight = Vector3.Cross(oldXZDir, aSM.transform.up).normalized;
|
||||
momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized;
|
||||
|
||||
if(oldXZDir != curXZDir){
|
||||
//midpointMom = swingMom;
|
||||
swingback = false;
|
||||
//Debug.Log("flip");
|
||||
}
|
||||
|
||||
if(swingback == false && swingMom <= (oldSwingMom*(.75f))){
|
||||
swingback = true;
|
||||
//if player is on the other side of hookpoint and swingMom is lower then update oldXZDir
|
||||
if(oldXZDir != curXZDir && swingMom <= (oldSwingMom*(.75f))){
|
||||
oldSwingMom = swingMom;
|
||||
oldXZDir = (new Vector3(aSM.hookPoint.transform.position.x,0,aSM.hookPoint.transform.position.z) - new Vector3(aSM.transform.position.x,0,aSM.transform.position.z)).normalized;
|
||||
//Debug.Log("swingback");
|
||||
}
|
||||
|
||||
//current line between hookpoint and player
|
||||
curXZDir = (new Vector3(hPoint.x,0,hPoint.z) - new Vector3(aSM.transform.position.x,0,aSM.transform.position.z)).normalized;
|
||||
Debug.DrawRay(aSM.transform.position, momDirection * Time.deltaTime* 100, Color.green);
|
||||
|
||||
//return momentum dir * mom force
|
||||
return (momDirection * Time.deltaTime * swingMom);
|
||||
|
||||
}
|
||||
|
||||
//Calculates the players initial swing momentum using their height and their current velocity
|
||||
@@ -165,11 +178,15 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
swingHeight = 1;
|
||||
}
|
||||
|
||||
float sMom = playerSpeed + (swingHeight*2);
|
||||
//calculates swing momentum based on height ands speed
|
||||
float sMom = playerSpeed + (swingHeight * 2.5f);
|
||||
if(sMom > aSM.maxSwingMom){
|
||||
sMom = aSM.maxSwingMom;
|
||||
}
|
||||
|
||||
//returns swing momentum
|
||||
return sMom;
|
||||
|
||||
}
|
||||
|
||||
//Special movement for the player while they swing
|
||||
@@ -197,14 +214,12 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
//Swing direction based on player input
|
||||
swingDirection = Vector3.Cross(tensionDirection, ((aSM.transform.right * -inputVert) + (aSM.transform.forward * inputHor))).normalized;
|
||||
|
||||
|
||||
//NEED TO ADD SWINGSPEED EASING
|
||||
//this could be just adding a gradual increase in the swing speed instead of using a flat rate
|
||||
//Swing movement with swing speed added
|
||||
Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed);
|
||||
|
||||
|
||||
//returns swing movement vector
|
||||
return (swingMovement);
|
||||
|
||||
}
|
||||
|
||||
Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance, AerialStateManager aSM){
|
||||
@@ -215,19 +230,24 @@ public class AerialGrappleAirState : AerialBaseState
|
||||
//The direction we need to apply force to offset when the rope gets lengthened beyond the necessary point
|
||||
Vector3 tenDirOffset = (hPoint - aSM.transform.position).normalized;
|
||||
|
||||
|
||||
//returns rope offset direction * power
|
||||
return tenDirOffset * offsetPower * Time.deltaTime;
|
||||
|
||||
}
|
||||
|
||||
Vector3 CalculateSwingReleaseForce(){
|
||||
|
||||
|
||||
//Swing release direction
|
||||
Vector3 releaseSwingForceDirection = momDirection * ((swingMom) + 10);
|
||||
|
||||
releaseSwingForceDirection = new Vector3(releaseSwingForceDirection.x,0,releaseSwingForceDirection.z);
|
||||
|
||||
if(swingMom < 5){
|
||||
//if swingMom is low there is no release force
|
||||
if(swingMom < 2){
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
//return swing release direction
|
||||
return releaseSwingForceDirection * Time.deltaTime;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ public class AerialGrappleGroundedState : AerialBaseState
|
||||
{
|
||||
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
|
||||
|
||||
aSM.release = false;
|
||||
aSM.release = false; // release is false when grounded
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
|
||||
@@ -14,25 +15,32 @@ public class AerialGrappleGroundedState : AerialBaseState
|
||||
}
|
||||
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
if(!aSM.isGrounded && aSM.pStats.GravVel < 0){
|
||||
|
||||
//if E is pressed or ragdolling then grounded
|
||||
if(((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld) || (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(Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position) > aSM.maxGrappleDistance){
|
||||
//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);
|
||||
}
|
||||
|
||||
if((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2))){
|
||||
aSM.eHeld = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(AerialStateManager aSM){
|
||||
Debug.DrawRay(aSM.transform.position, (aSM.hookPoint.transform.position - aSM.transform.position)); //Visual of line
|
||||
|
||||
//Default gravity calculation
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ using UnityEngine;
|
||||
|
||||
public class AerialWallRunState : AerialBaseState
|
||||
{
|
||||
|
||||
bool spaceHeld = true;
|
||||
|
||||
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
|
||||
|
||||
aSM.pStats.GravVel = 0;
|
||||
aSM.pStats.GravVel = 0; // on entering reset grav vel
|
||||
spaceHeld = true; // prevent accidental wall jumping
|
||||
|
||||
}
|
||||
|
||||
@@ -16,19 +18,31 @@ public class AerialWallRunState : AerialBaseState
|
||||
}
|
||||
|
||||
public override void UpdateState(AerialStateManager aSM){
|
||||
if(Input.GetButton("Jump")){
|
||||
|
||||
//if not wallrunning or are ragdolling then falling
|
||||
if(!aSM.isWallRunning || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
|
||||
//if space is pressed then jumping
|
||||
else if(Input.GetButton("Jump") && !spaceHeld){
|
||||
aSM.SwitchState(aSM.JumpingState);
|
||||
}
|
||||
else if(!aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
else if(!Input.GetButton("Jump") && spaceHeld){
|
||||
spaceHeld = false;
|
||||
}
|
||||
|
||||
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
|
||||
//if able to grapple then grapple
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(AerialStateManager aSM){
|
||||
|
||||
//Modified gravity calculation for wallrun
|
||||
aSM.GravityCalculation(2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user