Finished the Movement and Aerial groups

Working on the Dash, Nitro, and offense groups now
This commit is contained in:
Melbyj1125
2022-02-15 21:19:12 -06:00
parent ba3ac228f7
commit 833183d034
81 changed files with 1568 additions and 173 deletions

View File

@@ -4,10 +4,14 @@ using UnityEngine;
public class AerialFallingState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM){
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Falling State");
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
if(aSM.pStats.GravVel > 0){
aSM.SwitchState(aSM.JumpingState);
@@ -19,13 +23,21 @@ public class AerialFallingState : AerialBaseState
if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
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);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
public override void OnCollisionEnter(AerialStateManager aSM){
if(aSM.pStats.HasGrapple){
aSM.GrappleReleaseForce();
}
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);
}
}
}

View File

@@ -6,30 +6,40 @@ public class AerialGlidingState : AerialBaseState
{
float tempTraction;
public override void EnterState(AerialStateManager aSM){
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Gliding State");
tempTraction = aSM.pStats.Traction;
aSM.pStats.Traction = 1.0f;
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
aSM.pStats.Traction = tempTraction;
}
public override void UpdateState(AerialStateManager aSM){
if(!Input.GetButton("Jump")){
aSM.pStats.Traction = tempTraction;
aSM.SwitchState(aSM.FallingState);
}
if(aSM.isGrounded){
aSM.pStats.Traction = tempTraction;
aSM.SwitchState(aSM.GroundedState);
}
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(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
aSM.SwitchState(aSM.GrappleAirState);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
aSM.GravityCalculation(9);
}
public override void OnCollisionEnter(AerialStateManager aSM){
if(aSM.pStats.HasGrapple){
aSM.GrappleReleaseForce();
}
}
}

View File

@@ -4,8 +4,14 @@ using UnityEngine;
public class AerialGroundedState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM){
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Grounded State");
aSM.release = false;
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
@@ -15,13 +21,13 @@ public class AerialGroundedState : AerialBaseState
else if(aSM.pStats.GravVel > 0){
aSM.SwitchState(aSM.JumpingState);
}
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);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
public override void OnCollisionEnter(AerialStateManager aSM){
}
}

View File

@@ -5,10 +5,14 @@ using UnityEngine;
public class AerialJumpingState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM){
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Jumping State");
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
if(aSM.pStats.GravVel < 0){
@@ -18,13 +22,21 @@ public class AerialJumpingState : AerialBaseState
if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
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(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
aSM.SwitchState(aSM.GrappleAirState);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
public override void OnCollisionEnter(AerialStateManager aSM){
if(aSM.pStats.HasGrapple){
aSM.GrappleReleaseForce();
}
}
}

View File

@@ -4,8 +4,9 @@ using UnityEngine;
public abstract class AerialBaseState
{
public abstract void EnterState(AerialStateManager aSM);
public abstract void EnterState(AerialStateManager aSM, AerialBaseState previousState);
public abstract void ExitState(AerialStateManager aSM, AerialBaseState nextState);
public abstract void UpdateState(AerialStateManager aSM);
public abstract void FixedUpdateState(AerialStateManager aSM);
public abstract void OnCollisionEnter(AerialStateManager aSM);
}

View File

@@ -1,6 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using MLAPI;
using UnityEngine.Rendering;
public class AerialStateManager : MonoBehaviour
{
@@ -13,18 +16,26 @@ public class AerialStateManager : MonoBehaviour
public AerialGlidingState GlidingState = new AerialGlidingState();
public AerialGroundedState GroundedState = new AerialGroundedState();
public AerialJumpingState JumpingState = new AerialJumpingState();
//Wallrunning States
public AerialWallRunState WallRunState = new AerialWallRunState();
public AerialWallIdleState WallIdleState = new AerialWallIdleState();
//Grappling States
public AerialGrappleGroundedState GrappleGroundedState = new AerialGrappleGroundedState();
public AerialGrappleAirState GrappleAirState = new AerialGrappleAirState();
////
////Objects Sections
private GameObject parentObj; // Parent object
GameObject parentObj; // Parent object
public Camera cam; // Camera object
////
////Components Section
public CharacterController moveController; // Character Controller
private Rigidbody rB; // Players Rigidbody
private CapsuleCollider capCol; // Players Capsule Collider
private Animator animator; // Animation Controller
Rigidbody rB; // Players Rigidbody
CapsuleCollider capCol; // Players Capsule Collider
Animator animator; // Animation Controller
////
////Scripts Section
@@ -36,22 +47,61 @@ public class AerialStateManager : MonoBehaviour
//Jump Variables
public int curJumpNum; // current Jumps Used
public bool jumpHeld; // Jump is Held
private bool jumpPressed; // Jamp was pressed
bool jumpPressed; // Jamp was pressed
public float coyJumpTimer = 0.1f; // Default Coyote Jump time
public float curCoyJumpTimer = 0.1f; // current Coyote Jump time
public float lowJumpMultiplier; // Short jump multiplier
public float fallMultiplier; // High Jump Multiplier
//Gravity Variables//
private float maxG = -100; // max downwards velocity
float maxG = -100; // max downwards velocity
//Ground Check
public bool isGrounded; // is player grounded
public float groundCheckDistance = 0.05f; // offset distance to check ground
private const float jumpGroundingPreventionTime = 0.2f; // delay so player doesn't get snapped to ground while jumping
private const float groundCheckDistanceInAir = 0.07f; // How close we have to get to ground to start checking for grounded again
private Ray groundRay; // ground ray
private RaycastHit groundHit; // ground raycast
const float jumpGroundingPreventionTime = 0.2f; // delay so player doesn't get snapped to ground while jumping
const float groundCheckDistanceInAir = 0.07f; // How close we have to get to ground to start checking for grounded again
Ray groundRay; // ground ray
RaycastHit groundHit; // ground raycast
//Wallrun
float wallMaxDistance = 3f;
float wallSpeedMultiplier = 1.5f;
float minimumHeight = .1f;
[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;
//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 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;
////
void Awake(){
@@ -67,7 +117,7 @@ public class AerialStateManager : MonoBehaviour
////Initialize Scripts
pStats = GetComponent<PlayerStats>(); // set PlayerStats
mSM = GetComponent<MoveStateManager>();
mSM = GetComponent<MoveStateManager>(); // set move state manager
////
}
@@ -75,7 +125,21 @@ public class AerialStateManager : MonoBehaviour
//players starting state
currentState = GroundedState;
previousState = GroundedState;
currentState.EnterState(this);
currentState.EnterState(this, previousState);
////Initialize Variables
//Wallrun Variables
directions = new Vector3[]{
Vector3.right,
Vector3.right + Vector3.forward,
Vector3.forward,
Vector3.left + Vector3.forward,
Vector3.left
};
//Grapple Variables
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
////
}
void Update(){
@@ -85,10 +149,19 @@ public class AerialStateManager : MonoBehaviour
void FixedUpdate(){
//calls any logic in the fixed update state from current state
currentState.FixedUpdateState(this);
if(moveController.enabled){
Jump();
GroundCheck();
DownwardMovement();
if(pStats.HasWallrun){
WallRunRoutine();
}
//Dissipates Impact
DissipateImpact();
}
else{
//Gravity without moveController
@@ -97,20 +170,23 @@ public class AerialStateManager : MonoBehaviour
}
//calls any logic in the fixed update state from current state
currentState.FixedUpdateState(this);
}
public void SwitchState(AerialBaseState state){
currentState.ExitState(this, state);
//Sets the previous State
previousState = currentState;
//updates current state and calls logic for entering
currentState = state;
currentState.EnterState(this);
currentState.EnterState(this, previousState);
}
////Jump & Gravity Calculations
//Uses Given gravity to apply a downwards force while allowing coyote Jump and short hops
public void GravityCalculation(float grav){
if(moveController.enabled){
@@ -126,7 +202,7 @@ public class AerialStateManager : MonoBehaviour
}
//apply gravity if not grounded and coyote timer is less than 0
if((isGrounded == false && curCoyJumpTimer <= 0)/* || grapple.isGrappled*/){
if((isGrounded == false && curCoyJumpTimer <= 0) || currentState == GrappleAirState){
pStats.GravVel -= grav * Time.deltaTime;
}
//else don't apply gravity
@@ -157,7 +233,7 @@ public class AerialStateManager : MonoBehaviour
{
isGrounded = true;
// handle snapping to the ground
if (groundHit.distance > moveController.skinWidth /* && !grapple.isGrappled*/)
if (groundHit.distance > moveController.skinWidth && currentState != GrappleAirState)
{
moveController.Move(Vector3.down * groundHit.distance);
}
@@ -165,17 +241,34 @@ public class AerialStateManager : MonoBehaviour
}
}
private void DownwardMovement(){
//Actually applies the downwards movement
void DownwardMovement(){
Vector3 moveY = new Vector3(0,pStats.GravVel,0) * Time.deltaTime;
if(currentState == GrappleAirState){
moveY = (new Vector3(0,pStats.GravVel,0) + forceDirection) * Time.deltaTime;
}
moveController.Move(moveY);
}
private void Jump(){
//applies Jump values and Variables
void Jump(){
//If space/south gamepad button is pressed apply an upwards force to the player
if (Input.GetAxis("Jump") != 0 && !jumpHeld && curJumpNum < pStats.JumpNum)
{
pStats.GravVel = pStats.JumpPow;
if(currentState == WallRunState){
AddImpact((GetWallJumpDirection()), pStats.JumpPow * 8.5f);
pStats.GravVel = pStats.JumpPow;
curJumpNum = 0;
}
else{
pStats.GravVel = pStats.JumpPow;
}
curJumpNum++;
jumpHeld = true;
@@ -203,25 +296,211 @@ public class AerialStateManager : MonoBehaviour
}
}
/*
//Wallrunning
else if (pStats.HasWallrun) {
//Run wall run script
wallRun.WallRunRoutine();
//Apply Impact for when force needs to be applied without ragdolling
public void AddImpact(Vector3 dir, float force){
//if (!IsLocalPlayer) { return; }
//if wallrunning apply different gravity
if(wallRun.IsWallRunning()){
if(wallRun.firstAttach){
g = 0;
wallRun.firstAttach = false;
}
GravityCalculation(2);
//Normalize direction multiply by force and add it to the impact
dir.Normalize();
if (dir.y < 0) dir.y = -dir.y; // reflect down force on the ground
impact += dir.normalized * force / mass;
}
//Dissipates Impact Force
void DissipateImpact(){
//if suffiecient impact magnitude is applied then move player
if (impact.magnitude > 0.2F) moveController.Move(impact * Time.deltaTime);
// consumes the impact energy each cycle:
impact = Vector3.Lerp(impact, Vector3.zero, 5*Time.deltaTime);
}
////
////Wallrun Functions
//Checks if they can wallrun
public bool CanWallRun(){
float verticalAxis = Input.GetAxisRaw("Vertical");
return !isGrounded && verticalAxis > 0 && !Physics.Raycast(transform.position, Vector3.down, minimumHeight);
}
//checks if they can attach
bool CanAttach(){
if(jumping)
{
elapsedTimeSinceJump += Time.deltaTime;
if(elapsedTimeSinceJump > jumpDuration)
{
elapsedTimeSinceJump = 0;
jumping = false;
}
return false;
}
return true;
}
//On Wall calulations
void OnWall(RaycastHit hit){
float d = Vector3.Dot(hit.normal, Vector3.up);
if(d >= -normalizedAngleThreshold && d <= normalizedAngleThreshold)
{
Vector3 alongWall = Vector3.Cross(hit.normal, Vector3.up);
float vertical = Input.GetAxisRaw("Vertical");
//Vector3 alongWall = transform.TransformDirection(Vector3.forward);
// Debug.DrawRay(transform.position, alongWall.normalized * 10, Color.green);
// Debug.DrawRay(transform.position, lastWallNormal * 10, Color.magenta);
Vector3 moveToSet = alongWall * vertical * mSM.PlayerSpeed() * Time.deltaTime;
Vector3 velNorm = mSM.vel;
velNorm.Normalize();
moveToSet = new Vector3(moveToSet.x * -velNorm.x, moveToSet.y, moveToSet.z * -velNorm.z);
Vector3 moveToSetNorm = moveToSet;
moveToSetNorm.Normalize();
if((moveToSetNorm.x < 0 && velNorm.x > 0)){
moveToSet.x = (moveToSet.x * -velNorm.x);
}
else if((moveToSetNorm.x > 0 && velNorm.x < 0) ){
moveToSet.x = (-moveToSet.x * -velNorm.x);
}
//Normal gravity if not wallrunning
else{
GravityCalculation(pStats.PlayerGrav);
if((moveToSetNorm.z < 0 && velNorm.z > 0)){
moveToSet.z = (moveToSet.z * -velNorm.z);
}
else if((moveToSetNorm.z > 0 && velNorm.z < 0)){
moveToSet.z = (-moveToSet.z * -velNorm.z);
}
moveToSet.y = 0;
//
mSM.vel = moveToSet;
if(!isWallRunning){
isWallRunning = true;
}
if(curJumpNum == mSM.pStats.JumpNum){
curJumpNum = 0;
}
}
}
//Calculate wall direction
float CalculateSide(){
if(isWallRunning)
{
Vector3 heading = lastWallPosition - transform.position;
Vector3 perp = Vector3.Cross(transform.forward, heading);
float dir = Vector3.Dot(perp, transform.up);
return dir;
}
return 0;
}
//The Wallrun Routine itself
void WallRunRoutine(){
//if (!IsLocalPlayer) { return; }
isWallRunning = false;
hits = new RaycastHit[directions.Length];
if(jumpHeld)
{
jumping = true;
}
if(CanAttach())
{
for(int i=0; i<directions.Length; i++)
{
Vector3 dir = transform.TransformDirection(directions[i]);
Physics.Raycast(transform.position, dir, out hits[i], wallMaxDistance);
if(hits[i].collider != null)
{
Debug.DrawRay(transform.position, dir * hits[i].distance, Color.green);
}
else
{
Debug.DrawRay(transform.position, dir * wallMaxDistance, Color.red);
}
}
if(CanWallRun())
{
hits = hits.ToList().Where(h => h.collider != null).OrderBy(h => h.distance).ToArray();
if(hits.Length > 0)
{
if(hits[0].collider.tag == "WallRun")
{
OnWall(hits[0]);
lastWallPosition = hits[0].point;
lastWallNormal = hits[0].normal;
}
}
}
}
*/
if(isWallRunning)
{
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
}
}
//The Direction the player jumps on wall detachment
public Vector3 GetWallJumpDirection(){
return lastWallNormal * wallBouncing + (transform.up);
}
////
////Grapple Functions
//Checks if the player can grapple
public bool CheckGrapple(){
if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && pStats.HasGrapple) //If grapple button is hit
{
hookPointIndex = FindHookPoint(); //Find the nearest hook point within max distance
if (hookPointIndex != -1) //If there is a hookpoint
{
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
eHeld = true;
return true;
}
}
return false;
}
//Finds the nearest hook to the player
int FindHookPoint()
{
float least = maxGrabDistance;
int index = -1;
for(int i = 0; i<hookPoints.Length; i++)
{
distance = Vector3.Distance(gameObject.transform.position, hookPoints[i].transform.position);
if (distance <= least)
{
index = i;
}
}
return index;
}
public void GrappleReleaseForce(){
if(release){
lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 9f * Time.deltaTime);
tempRelease *= .98f;
moveController.Move(lerpRelease);
}
}
////
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d9e7839f6deda248905235a2cc3e3cf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,228 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AerialGrappleAirState : AerialBaseState
{
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;
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Grapple Air State");
aSM.curJumpNum = 0;
ropeLength = Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position);
if(ropeLength > aSM.maxGrappleDistance){
ropeLength = aSM.maxGrappleDistance;
}
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;
curXZDir = (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;
swingMom = CalculateSwingMom(aSM.mSM.driftVel.magnitude * 50f, aSM);
oldSwingMom = swingMom;
aSM.pStats.GravVel = -1;
aSM.release = false;
aSM.lerpRelease = Vector3.zero;
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
if(nextState != aSM.GrappleGroundedState){
aSM.release = true;
aSM.pStats.GravVel = 0;
aSM.forceDirection = Vector3.zero;
swingback = true;
}
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){
aSM.SwitchState(aSM.FallingState);
}
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2))){
aSM.eHeld = false;
}
if(Input.GetButton("Jump")){
aSM.SwitchState(aSM.JumpingState);
}
if(aSM.isGrounded){
aSM.SwitchState(aSM.GrappleGroundedState);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
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 )
{
aSM.forceDirection = CalculateForceDirection(1, aSM.pStats.GravVel, aSM.hookPoint.transform.position, aSM) + RopeLengthOffset(aSM.hookPoint.transform.position, Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position), aSM);
}
else{
aSM.forceDirection = Vector3.zero;
}
aSM.moveController.Move(SwingMoveController(aSM));
if(swingMom != 0){
aSM.moveController.Move(CalculateMomentumDirection(aSM.pStats.GravVel, aSM.hookPoint.transform.position, aSM));
swingMom -= .5f;
}
if(swingMom<0) swingMom = 0;
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)
//Calculate the tether direction vector and how much force that vector needs
Vector3 CalculateForceDirection(float mass, float g, Vector3 hPoint, AerialStateManager aSM){
//tension direction and angle calculation
tensionDirection = (hPoint - aSM.transform.position).normalized;
inclinationAngle = Vector3.Angle((aSM.transform.position - hPoint).normalized, -aSM.transform.up);
theta = Mathf.Deg2Rad * inclinationAngle;
if(theta<=.1) theta = 0;
//How much force the tension needs
tensionForce = mass * -g * Mathf.Cos(theta);
//force direction calculation based on tension direction and force
Vector3 fDirection = tensionDirection * tensionForce;
return fDirection;
}
Vector3 CalculateMomentumDirection(float g, Vector3 hPoint, AerialStateManager aSM){
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;
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");
}
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 (momDirection * Time.deltaTime * swingMom);
}
//Calculates the players initial swing momentum using their height and their current velocity
float CalculateSwingMom(float playerSpeed, AerialStateManager aSM){
//Calculate the players height compared to the lowest point in the swing
float swingHeight = aSM.transform.position.y - (aSM.hookPoint.transform.position.y - ropeLength);
if(swingHeight <= 1){
swingHeight = 1;
}
float sMom = playerSpeed + (swingHeight*2);
if(sMom > aSM.maxSwingMom){
sMom = aSM.maxSwingMom;
}
return sMom;
}
//Special movement for the player while they swing
Vector3 SwingMoveController(AerialStateManager aSM){
//WASD input
float inputVert = Input.GetAxis("Vertical");
float inputHor = Input.GetAxis("Horizontal");
//input is zero when nothing is pressed to prevent button easing values
if((!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))) inputVert = 0;
if((!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))) inputHor = 0;
//Swingspeed build up
if((inputVert != 0 || inputHor != 0) && swingSpeed < aSM.maxSwingSpeed){
swingSpeed += aSM.swingAcc;
}
else if((inputVert != 0 || inputHor != 0) && swingSpeed >= aSM.maxSwingSpeed){
swingSpeed = aSM.maxSwingSpeed;
}
else if((inputVert == 0 && inputHor == 0)){
swingSpeed = aSM.minSwingSpeed;
}
//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);
return (swingMovement);
}
Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance, AerialStateManager aSM){
//How powerful our offset movement has to be
float offsetPower = ((curDistance - ropeLength) * 200f);
//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;
return tenDirOffset * offsetPower * Time.deltaTime;
}
Vector3 CalculateSwingReleaseForce(){
Vector3 releaseSwingForceDirection = momDirection * ((swingMom) + 10);
releaseSwingForceDirection = new Vector3(releaseSwingForceDirection.x,0,releaseSwingForceDirection.z);
if(swingMom < 5){
return Vector3.zero;
}
return releaseSwingForceDirection * Time.deltaTime;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18f636cc4d77c0d439a1effaa5b08485
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AerialGrappleGroundedState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Grapple Grounded State");
aSM.release = false;
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
if(!aSM.isGrounded && aSM.pStats.GravVel < 0){
aSM.SwitchState(aSM.GrappleAirState);
}
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
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd53fea25f9a40e41812e6faae369b2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7bdb37848afbcd446b59b3158927a111
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AerialWallIdleState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
}
public override void FixedUpdateState(AerialStateManager aSM){
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15b109cc50982684c9d17a41ec11dc32
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AerialWallRunState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
Debug.Log("Wallrun State");
aSM.pStats.GravVel = 0;
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
}
public override void UpdateState(AerialStateManager aSM){
if(Input.GetButton("Jump")){
aSM.SwitchState(aSM.JumpingState);
}
else if(!aSM.isWallRunning){
aSM.SwitchState(aSM.FallingState);
}
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);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
aSM.GravityCalculation(2);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 93ab0a7ac87da66408ced3667ae9b930
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: