mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 01:44:30 -05:00
created a debug prefab
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3dd0e9bfb82a6a1479a798cb507f75b3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialFallingState : dAerialBaseState
|
||||
{
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//if Grav Vel > 0 then jumping
|
||||
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
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if is wallrunning ands is in a state that allows it wallrun
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
//Default gravity calculation
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
|
||||
//if grapple released apply release force
|
||||
if(aSM.pStats.HasGrapple){
|
||||
aSM.GrappleReleaseForce();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6722fdbb94c5381478060247e52825a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialGlidingState : dAerialBaseState
|
||||
{
|
||||
float tempTraction; // temp traction to store the actual player traction
|
||||
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
//Modify base traction
|
||||
tempTraction = aSM.pStats.Traction;
|
||||
aSM.pStats.Traction = 1.0f;
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
//return traction to normal
|
||||
aSM.pStats.Traction = tempTraction;
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//if not holding jump fall
|
||||
if(!Input.GetButton("Jump") || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
|
||||
//if is grounded then grounded
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if isWallrunning and in state that allows it wallrun
|
||||
else if(aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
//if can grapple and in state that allows it grapple
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
//modified gravity calculation to fall slower
|
||||
aSM.GravityCalculation(9);
|
||||
|
||||
//if grapple released apply release force
|
||||
if(aSM.pStats.HasGrapple){
|
||||
aSM.GrappleReleaseForce();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca88991fb50bfa3448684da56843b7c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialGroundedState : dAerialBaseState
|
||||
{
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
//release is false if grounded
|
||||
aSM.release = false;
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//if grav vel < 0 then falling
|
||||
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 && (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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
//base gravity calculations
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f824e83f9c831674c9253c243b68f8c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialJumpingState : dAerialBaseState
|
||||
{
|
||||
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//if grav vel < 0 falling
|
||||
if(aSM.pStats.GravVel < 0 || aSM.mSM.currentState == aSM.mSM.RagdollState){
|
||||
aSM.SwitchState(aSM.FallingState);
|
||||
}
|
||||
|
||||
//if is grounded then grounded
|
||||
else if(aSM.isGrounded){
|
||||
aSM.SwitchState(aSM.GroundedState);
|
||||
}
|
||||
|
||||
//if is wall running and in a state that allows it wallrun
|
||||
else if(aSM.isWallRunning){
|
||||
aSM.SwitchState(aSM.WallRunState);
|
||||
}
|
||||
|
||||
//if can grapple and in a state that allows it grapple
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
//default gravity calculations
|
||||
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
|
||||
|
||||
//if grapple release then apply grapple release force
|
||||
if(aSM.pStats.HasGrapple){
|
||||
aSM.GrappleReleaseForce();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8aafe153a83557c41a009cceb1732e4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52972830fdc64d84daf7f72a716ed494
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,253 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialGrappleAirState : dAerialBaseState
|
||||
{
|
||||
|
||||
bool spaceHeld = true;
|
||||
float ropeLength; // current rope length
|
||||
float inclinationAngle; // inclination angle
|
||||
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(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
//refresh jump number
|
||||
aSM.curJumpNum = 0;
|
||||
|
||||
//rope length limit
|
||||
ropeLength = Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position);
|
||||
if(ropeLength > aSM.maxGrappleDistance){
|
||||
ropeLength = aSM.maxGrappleDistance;
|
||||
}
|
||||
|
||||
//old and cur direction vector for player to hookpoint
|
||||
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;
|
||||
|
||||
//swing momentum calculation
|
||||
swingMom = CalculateSwingMom(aSM.mSM.driftVel.magnitude * 50f, aSM);
|
||||
oldSwingMom = swingMom;
|
||||
|
||||
//Initialize variables
|
||||
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(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
//If not going into grapple grounded state
|
||||
if(nextState != aSM.GrappleGroundedState){
|
||||
aSM.release = true;
|
||||
aSM.pStats.GravVel = 0;
|
||||
aSM.forceDirection = Vector3.zero;
|
||||
}
|
||||
|
||||
//If going into grapple grounded state
|
||||
else{
|
||||
aSM.pStats.GravVel = 0;
|
||||
aSM.forceDirection = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//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)) && aSM.eHeld){
|
||||
aSM.eHeld = false;
|
||||
}
|
||||
|
||||
//if pressing Jump then jump
|
||||
else if(Input.GetButton("Jump") && !spaceHeld){
|
||||
aSM.SwitchState(aSM.JumpingState);
|
||||
}
|
||||
else if(!(Input.GetButton("Jump")) && spaceHeld){
|
||||
spaceHeld = false;
|
||||
}
|
||||
|
||||
//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(dAerialStateManager 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
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
//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();
|
||||
|
||||
//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, dAerialStateManager 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 force direction
|
||||
return fDirection;
|
||||
|
||||
}
|
||||
|
||||
Vector3 CalculateMomentumDirection(float g, Vector3 hPoint, dAerialStateManager aSM){
|
||||
|
||||
tensionMomDirection = (hPoint - aSM.transform.position).normalized;
|
||||
hookPointRight = Vector3.Cross(oldXZDir, aSM.transform.up).normalized;
|
||||
momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
//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
|
||||
float CalculateSwingMom(float playerSpeed, dAerialStateManager 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;
|
||||
}
|
||||
|
||||
//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
|
||||
Vector3 SwingMoveController(dAerialStateManager 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;
|
||||
|
||||
//Swing movement with swing speed added
|
||||
Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed);
|
||||
|
||||
//returns swing movement vector
|
||||
return (swingMovement);
|
||||
|
||||
}
|
||||
|
||||
Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance, dAerialStateManager 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;
|
||||
|
||||
//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 is low there is no release force
|
||||
if(swingMom < 2){
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
//return swing release direction
|
||||
return releaseSwingForceDirection * Time.deltaTime;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0b365af54acfc546a6f5e6058270882
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 080d941405d7f1d41bf2647c10ddc38e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a887c15969bc4b4786be862437bf8d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialWallIdleState : dAerialBaseState
|
||||
{
|
||||
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12bfb64019585454cae0871e081e007d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dAerialWallRunState : dAerialBaseState
|
||||
{
|
||||
bool spaceHeld = true;
|
||||
|
||||
public override void EnterState(dAerialStateManager aSM, dAerialBaseState previousState){
|
||||
|
||||
aSM.pStats.GravVel = 0; // on entering reset grav vel
|
||||
spaceHeld = true; // prevent accidental wall jumping
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dAerialStateManager aSM, dAerialBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dAerialStateManager aSM){
|
||||
|
||||
//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(!Input.GetButton("Jump") && spaceHeld){
|
||||
spaceHeld = false;
|
||||
}
|
||||
|
||||
//if able to grapple then grapple
|
||||
else if(aSM.CheckGrapple()){
|
||||
aSM.SwitchState(aSM.GrappleAirState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dAerialStateManager aSM){
|
||||
|
||||
//Modified gravity calculation for wallrun
|
||||
aSM.GravityCalculation(2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c42c07686ce0844baee41facfcda6fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class dAerialBaseState
|
||||
{
|
||||
public abstract void EnterState(dAerialStateManager aSM, dAerialBaseState previousState);
|
||||
public abstract void ExitState(dAerialStateManager aSM, dAerialBaseState nextState);
|
||||
public abstract void UpdateState(dAerialStateManager aSM);
|
||||
public abstract void FixedUpdateState(dAerialStateManager aSM);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93c036f34a4238f42bc6f28d1c94756e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,518 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using MLAPI;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class dAerialStateManager : NetworkBehaviour
|
||||
{
|
||||
////Player States
|
||||
public dAerialBaseState currentState;
|
||||
public dAerialBaseState previousState;
|
||||
|
||||
//Aerial States
|
||||
public dAerialFallingState FallingState = new dAerialFallingState();
|
||||
public dAerialGlidingState GlidingState = new dAerialGlidingState();
|
||||
public dAerialGroundedState GroundedState = new dAerialGroundedState();
|
||||
public dAerialJumpingState JumpingState = new dAerialJumpingState();
|
||||
|
||||
//Wallrunning States
|
||||
public dAerialWallRunState WallRunState = new dAerialWallRunState();
|
||||
public dAerialWallIdleState WallIdleState = new dAerialWallIdleState();
|
||||
|
||||
//Grappling States
|
||||
public dAerialGrappleGroundedState GrappleGroundedState = new dAerialGrappleGroundedState();
|
||||
public dAerialGrappleAirState GrappleAirState = new dAerialGrappleAirState();
|
||||
////
|
||||
|
||||
////Objects Sections
|
||||
GameObject parentObj; // Parent object
|
||||
////
|
||||
|
||||
////Components Section
|
||||
public CharacterController moveController; // Character Controller
|
||||
Rigidbody rB; // Players Rigidbody
|
||||
Animator animator; // Animation Controller
|
||||
////
|
||||
|
||||
////Scripts Section
|
||||
public PlayerStats pStats; // Player Stats
|
||||
public dMoveStateManager mSM;
|
||||
////
|
||||
|
||||
////Variables Section
|
||||
//Jump Variables
|
||||
public int curJumpNum; // current Jumps Used
|
||||
public bool jumpHeld; // Jump is Held
|
||||
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//
|
||||
float maxG = -100; // max downwards velocity
|
||||
|
||||
//Ground Check
|
||||
public bool isGrounded; // is player grounded
|
||||
public float groundCheckDistance = 0.05f; // offset distance to check ground
|
||||
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; // 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; // 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 = 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 = 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(){
|
||||
|
||||
////Initialize Player Components
|
||||
moveController = GetComponent<CharacterController>(); // set Character Controller
|
||||
rB = GetComponent<Rigidbody>(); //set Rigid Body
|
||||
parentObj = transform.parent.gameObject; // set parent object
|
||||
animator = GetComponent<Animator>(); // set animator
|
||||
////
|
||||
|
||||
////Initialize Scripts
|
||||
pStats = GetComponent<PlayerStats>(); // set PlayerStats
|
||||
mSM = GetComponent<dMoveStateManager>(); // set move state manager
|
||||
////
|
||||
}
|
||||
|
||||
void Start(){
|
||||
//players starting state
|
||||
currentState = GroundedState;
|
||||
previousState = GroundedState;
|
||||
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(){
|
||||
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
//calls any logic in the update state from current state
|
||||
currentState.UpdateState(this);
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
//Dissipates Impact
|
||||
DissipateImpact();
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
//Gravity without moveController
|
||||
pStats.GravVel -= pStats.PlayerGrav * Time.deltaTime;
|
||||
rB.AddForce(new Vector3(0,pStats.GravVel,0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SwitchState(dAerialBaseState state){
|
||||
|
||||
currentState.ExitState(this, state);
|
||||
|
||||
//Sets the previous State
|
||||
previousState = currentState;
|
||||
|
||||
//updates current state and calls logic for entering
|
||||
currentState = state;
|
||||
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){
|
||||
|
||||
//apply slight upwards force for jump smoothing when g < 0
|
||||
if(pStats.GravVel < 0){
|
||||
pStats.GravVel += grav * (fallMultiplier - 1) * Time.deltaTime;
|
||||
}
|
||||
|
||||
//apply smaller upwards force if jump is released early when jumping creating a short jump
|
||||
else if (pStats.GravVel > 0 && !Input.GetButton("Jump")){
|
||||
pStats.GravVel += grav * (lowJumpMultiplier - 1) * Time.deltaTime;
|
||||
}
|
||||
|
||||
//apply gravity if not grounded and coyote timer is less than 0
|
||||
if((isGrounded == false && curCoyJumpTimer <= 0) || currentState == GrappleAirState){
|
||||
pStats.GravVel -= grav * Time.deltaTime;
|
||||
}
|
||||
//else don't apply gravity
|
||||
else{
|
||||
pStats.GravVel = 0;
|
||||
}
|
||||
|
||||
//Caps out the players downwards speed
|
||||
if(pStats.GravVel < maxG){
|
||||
pStats.GravVel = maxG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Checks if player is grounded
|
||||
void GroundCheck(){
|
||||
// Make sure that the ground check distance while already in air is very small, to prevent suddenly snapping to ground
|
||||
float chosenGroundCheckDistance = isGrounded ? (moveController.skinWidth + groundCheckDistance) : groundCheckDistanceInAir;
|
||||
|
||||
// reset values before the ground check
|
||||
isGrounded = false;
|
||||
groundRay = new Ray(moveController.transform.position, Vector3.down);
|
||||
|
||||
if (Physics.Raycast(groundRay, out groundHit, moveController.height + groundCheckDistance) && !jumpPressed)
|
||||
{
|
||||
// Only consider this a valid ground hit if the ground normal goes in the same direction as the character up
|
||||
if (Vector3.Dot(groundHit.normal, transform.up) > 0f)
|
||||
{
|
||||
isGrounded = true;
|
||||
// handle snapping to the ground
|
||||
if (groundHit.distance > moveController.skinWidth && currentState != GrappleAirState)
|
||||
{
|
||||
moveController.Move(Vector3.down * groundHit.distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
if(currentState == WallRunState){
|
||||
AddImpact((GetWallJumpDirection()), pStats.JumpPow * 8.5f);
|
||||
pStats.GravVel = pStats.JumpPow;
|
||||
curJumpNum = 0;
|
||||
}
|
||||
else{
|
||||
pStats.GravVel = pStats.JumpPow;
|
||||
}
|
||||
|
||||
|
||||
curJumpNum++;
|
||||
jumpHeld = true;
|
||||
jumpPressed = true;
|
||||
}
|
||||
|
||||
//If grounded no jumps have been used and coyote Timer is refreshed
|
||||
if(isGrounded && pStats.GravVel == 0){
|
||||
curCoyJumpTimer = coyJumpTimer;
|
||||
curJumpNum = 0;
|
||||
}
|
||||
//else start the coyote timer
|
||||
else curCoyJumpTimer -= Time.deltaTime;
|
||||
|
||||
//if jump is being held coyote timer is zero
|
||||
if(jumpHeld) curCoyJumpTimer = 0;
|
||||
|
||||
//If space/south face gamepad button isn't being pressed then jump is false
|
||||
if (Input.GetAxis("Jump") == 0){
|
||||
jumpHeld = false;
|
||||
}
|
||||
|
||||
if(pStats.GravVel < 0){
|
||||
jumpPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Apply Impact for when force needs to be applied without ragdolling
|
||||
public void AddImpact(Vector3 dir, float force){
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
////
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ec82a74ea7992f44b37925faefa63b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user