mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 18:04:27 -05:00
reworked grapple functionally more of a hookshot
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user