mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 09:54:28 -05:00
created a debug prefab
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf5c68e36c240fd4d9b4e0d050b61ff6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d4a65cb1b20bfa4689e1a856baa9c87
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc7d359bb4c2d59458400abdc3083871
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dDashCooldownState : dDashBaseState
|
||||
{
|
||||
bool cooldown = false; // is cooldown over
|
||||
|
||||
public override void EnterState(dDashStateManager dSM, dDashBaseState previousState){
|
||||
cooldown = false; // sets cooldown
|
||||
dSM.StartCoroutine(startCoolDown(dSM)); // activates cooldown
|
||||
}
|
||||
|
||||
public override void ExitState(dDashStateManager dSM, dDashBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dDashStateManager dSM){
|
||||
|
||||
//if after cooldown player is incapacitated still then Incapacitated
|
||||
if(cooldown && (dSM.mSM.currentState == dSM.mSM.RagdollState || dSM.mSM.currentState == dSM.mSM.RecoveringState || dSM.mSM.currentState == dSM.mSM.SlideState || dSM.mSM.currentState == dSM.mSM.CrouchState || dSM.mSM.currentState == dSM.mSM.CrouchWalkState)){
|
||||
dSM.SwitchState(dSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if cooldown is over then None
|
||||
else if(cooldown){
|
||||
dSM.SwitchState(dSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dDashStateManager dSM){
|
||||
|
||||
}
|
||||
|
||||
//cooldown function
|
||||
private IEnumerator startCoolDown(dDashStateManager dSM){
|
||||
//dSM.driver.startUICooldown(dashItem.name);
|
||||
yield return new WaitForSeconds(dSM.dashItem.cooldownM);
|
||||
cooldown = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa9f95b37196a914db649108d4732827
|
||||
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 dDashDashingState : dDashBaseState
|
||||
{
|
||||
|
||||
Vector3 moveDirection; // direction vector
|
||||
const float maxDashTime = .8f; // max dash time
|
||||
float dashDistance = 10; // distance to dash
|
||||
float dashStoppingSpeed = 0.1f; // how quickly they stop
|
||||
float currentDashTime = maxDashTime; // current dash time
|
||||
float dashSpeed = 12; // dash speed
|
||||
|
||||
public override void EnterState(dDashStateManager dSM, dDashBaseState previousState){
|
||||
currentDashTime = 0; // resets dash time
|
||||
}
|
||||
|
||||
public override void ExitState(dDashStateManager dSM, dDashBaseState nextState){
|
||||
moveDirection = Vector3.zero; // resets moveDirection
|
||||
}
|
||||
|
||||
public override void UpdateState(dDashStateManager dSM){
|
||||
//if dash timer is active then move player
|
||||
if(currentDashTime < maxDashTime){
|
||||
moveDirection = dSM.transform.forward * dashDistance;
|
||||
currentDashTime += dashStoppingSpeed;
|
||||
}
|
||||
|
||||
//if dashtimer runs out then cooldown
|
||||
else{
|
||||
dSM.SwitchState(dSM.CooldownState);
|
||||
}
|
||||
|
||||
//if player becomes incapacitated then cooldown
|
||||
if(dSM.mSM.currentState == dSM.mSM.RagdollState || dSM.mSM.currentState == dSM.mSM.SlideState || dSM.mSM.currentState == dSM.mSM.CrouchState || dSM.mSM.currentState == dSM.mSM.CrouchWalkState){
|
||||
dSM.SwitchState(dSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dDashStateManager dSM){
|
||||
|
||||
//Actually moves the player
|
||||
dSM.moveController.Move(moveDirection * Time.deltaTime * dashSpeed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56ebe9dc3558ad84998741b5be0cda1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dDashIncapacitatedState : dDashBaseState
|
||||
{
|
||||
public override void EnterState(dDashStateManager dSM, dDashBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dDashStateManager dSM, dDashBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dDashStateManager dSM){
|
||||
|
||||
//if no longer incapacitated then None
|
||||
if(dSM.mSM.currentState != dSM.mSM.RagdollState && dSM.mSM.currentState != dSM.mSM.RecoveringState && dSM.mSM.currentState != dSM.mSM.SlideState && dSM.mSM.currentState != dSM.mSM.CrouchState && dSM.mSM.currentState != dSM.mSM.CrouchWalkState){
|
||||
dSM.SwitchState(dSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dDashStateManager dSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3980edf85fc6c74595f75901648239b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dDashNoneState : dDashBaseState
|
||||
{
|
||||
public override void EnterState(dDashStateManager dSM, dDashBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dDashStateManager dSM, dDashBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dDashStateManager dSM){
|
||||
|
||||
//checks if player has dash
|
||||
if(dSM.pStats.HasDash){
|
||||
|
||||
//if incapacitated then incapacitated
|
||||
if(dSM.mSM.currentState == dSM.mSM.RagdollState || dSM.mSM.currentState == dSM.mSM.SlideState || dSM.mSM.currentState == dSM.mSM.CrouchState || dSM.mSM.currentState == dSM.mSM.CrouchWalkState){
|
||||
dSM.SwitchState(dSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if R key then Dashing
|
||||
else if ((Input.GetKeyDown(KeyCode.R) || Input.GetAxis("Dash") != 0)){
|
||||
dSM.SwitchState(dSM.DashingState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dDashStateManager dSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f665861e6fe6d10448d94669cb14ba01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class dDashBaseState
|
||||
{
|
||||
public abstract void EnterState(dDashStateManager dSM, dDashBaseState previousState);
|
||||
public abstract void ExitState(dDashStateManager dSM, dDashBaseState nextState);
|
||||
public abstract void UpdateState(dDashStateManager dSM);
|
||||
public abstract void FixedUpdateState(dDashStateManager dSM);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3113ef1d29d60964989ec1a7429b88fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
|
||||
public class dDashStateManager : NetworkBehaviour
|
||||
{
|
||||
////Player States
|
||||
public dDashBaseState currentState;
|
||||
public dDashBaseState previousState;
|
||||
|
||||
//Dash States
|
||||
public dDashNoneState NoneState = new dDashNoneState();
|
||||
public dDashIncapacitatedState IncapacitatedState = new dDashIncapacitatedState();
|
||||
public dDashCooldownState CooldownState = new dDashCooldownState();
|
||||
public dDashDashingState DashingState = new dDashDashingState();
|
||||
////
|
||||
|
||||
////Components Section
|
||||
public CharacterController moveController; // Character Controller
|
||||
Animator animator; // Animation Controller
|
||||
////
|
||||
|
||||
////Scripts Section
|
||||
public PlayerStats pStats; // Player Stats
|
||||
public dMoveStateManager mSM; // movement state manager
|
||||
public CoolDown driver; // cooldown driver
|
||||
////
|
||||
|
||||
////Items Section
|
||||
public SpecialItem dashItem; // dash item
|
||||
////
|
||||
|
||||
void Awake(){
|
||||
|
||||
////Initialize Player Components
|
||||
moveController = GetComponent<CharacterController>(); // set Character Controller
|
||||
animator = GetComponent<Animator>(); // set animator
|
||||
//driver = GameObject.Find("Canvas").GetComponent<CoolDown>();
|
||||
////
|
||||
|
||||
////Initialize Scripts
|
||||
pStats = GetComponent<PlayerStats>(); // set PlayerStats
|
||||
mSM = GetComponent<dMoveStateManager>(); // set move state manager
|
||||
////
|
||||
}
|
||||
|
||||
void Start(){
|
||||
//players starting state
|
||||
currentState = NoneState;
|
||||
previousState = NoneState;
|
||||
currentState.EnterState(this, previousState);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void SwitchState(dDashBaseState 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1cd2fe42d6a34c43bc4a8b65dfaf533
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd9b3de0a138bb04085f406977c19fc2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63098b3acaf04be4196860ffe4d590b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveGrappleAirState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
mSM.driftVel = Vector3.zero; // clears driftVel
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//checks if aerial state manager is no longer air grappling
|
||||
if(mSM.aSM.currentState != mSM.aSM.GrappleAirState){
|
||||
//Determine which state to go into based on player speed
|
||||
if(mSM.calculatedCurVel < mSM.walkLimit){
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
else if(mSM.calculatedCurVel < mSM.runLimit){
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
else{
|
||||
mSM.SwitchState(mSM.RunState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
//Directional movement to prevent weird movement issue
|
||||
mSM.DirectionalMovement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc780835fa45ef446ae5d2b3594a171f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f072fdd4378642b45b9ae0387da42e0c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveRagdollState : dMoveBaseState
|
||||
{
|
||||
|
||||
float ragTime; // ragdoll timer
|
||||
Vector3 prevRot; // previous rotation before ragdolled
|
||||
bool beginRagTimer = false; // whether ragtimer has started
|
||||
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
ragTime = mSM.pStats.RecovTime; // how long to be ragdolled
|
||||
prevRot = mSM.transform.localEulerAngles; // save previous rotation
|
||||
mSM.capCol.enabled = true; // enable capsule collider
|
||||
mSM.moveController.enabled = false; // disable move controller
|
||||
mSM.rB.isKinematic = false; // disable kinematic
|
||||
mSM.rB.detectCollisions = true; // detect collisions
|
||||
|
||||
//apply force
|
||||
mSM.rB.AddForce(mSM.dirHit, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
mSM.pStats.GravVel = 50; // resets gravVel
|
||||
mSM.capCol.enabled = false; // disable capsule collider
|
||||
mSM.moveController.enabled = true; // enable move controller
|
||||
mSM.rB.isKinematic = true; // enable kinematic
|
||||
mSM.rB.detectCollisions = false; // detect collisions false
|
||||
mSM.transform.localEulerAngles = prevRot; // reset player rotation
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//if player hasn't touched the ground don't start timer
|
||||
if(!beginRagTimer){
|
||||
beginRagTimer = Physics.Raycast(mSM.transform.position, -Vector3.up, mSM.distToGround + 1f);
|
||||
}
|
||||
|
||||
//start timer
|
||||
else{
|
||||
ragTime -= Time.deltaTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
//if ragtimer is over then recover
|
||||
if(ragTime <= 0 && beginRagTimer){
|
||||
ragTime = 0;
|
||||
beginRagTimer = false;
|
||||
|
||||
mSM.SwitchState(mSM.RecoveringState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a433937d5c90394886371cef684677b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveRecoveringState : dMoveBaseState
|
||||
{
|
||||
////// ADD SOMETHING THAT CHECKS ANIMATION FINISH BEFORE GO TO IDLE
|
||||
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
mSM.CancelMomentum(); // reset player variables
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//swap to idle state
|
||||
mSM.SwitchState(mSM.IdleState);
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16249e3341f73f64c968404554cbee6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aee8a986bb3d20b4d9bc8838fe1ceae1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveCrouchState : dMoveBaseState
|
||||
{
|
||||
|
||||
//Slide Variables
|
||||
RaycastHit slideRay; // slide raycast
|
||||
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
//if not coming from slide state then rotate player and adjust height
|
||||
if(previousState != mSM.SlideState){
|
||||
mSM.pStats.CurVel = 0;
|
||||
mSM.gameObject.transform.eulerAngles = new Vector3(mSM.transform.localEulerAngles.x - 90, mSM.transform.localEulerAngles.y, mSM.transform.localEulerAngles.z);
|
||||
mSM.moveController.height *= .5f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
//if next state isn't crouch walk revert rotation, speed, and height
|
||||
if(nextState != mSM.CrouchWalkState){
|
||||
mSM.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
|
||||
mSM.pStats.CurVel = mSM.calculatedCurVel;
|
||||
mSM.moveController.height *= 2.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
mSM.transform.Rotate(Vector3.forward * -mSM.sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
|
||||
|
||||
///////ONCE WE HAVE IT SO SLIDE DOESNT ROTATE PLAYER MOVE THIS TO UPDATE
|
||||
//If player isn't pressing either Q or the joystick button they stop crouching if nothing is above them
|
||||
if((!Input.GetKey(KeyCode.JoystickButton1) && !Input.GetKey(KeyCode.Q))){
|
||||
if ((Physics.Raycast(mSM.gameObject.transform.position, mSM.slideUp, out slideRay, 5f) == false)){
|
||||
|
||||
mSM.SwitchState(mSM.IdleState);
|
||||
}
|
||||
else{
|
||||
Debug.Log("Object above you");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//If falling stop sliding and go to wasd states
|
||||
if(mSM.aSM.currentState == mSM.aSM.FallingState){
|
||||
ExitCrouchState(mSM);
|
||||
mSM.SwitchState(mSM.IdleState);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68982636ca83cdf4a951928206dd334f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveCrouchWalkState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
/*
|
||||
if(mSM.aSM.currentState == mSM.aSM.FallingState){
|
||||
//Determine which state to go into based on player speed
|
||||
if(mSM.calculatedCurVel < mSM.walkLimit){
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
else if(mSM.calculatedCurVel < mSM.runLimit){
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
else{
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.RunState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ace36bef6e24634d9c051e1530efd99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,97 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveSlideState : dMoveBaseState
|
||||
{
|
||||
//Slide Variables
|
||||
float originalTraction; // Traction before slide started
|
||||
RaycastHit slideRay; // slide raycast
|
||||
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
//Rotate player and adjust height and adjust traction
|
||||
mSM.pStats.CurVel = 0;
|
||||
originalTraction = mSM.pStats.Traction;
|
||||
mSM.gameObject.transform.eulerAngles = new Vector3(mSM.transform.eulerAngles.x - 90, mSM.transform.eulerAngles.y, mSM.transform.eulerAngles.z);
|
||||
mSM.moveController.height *= .5f;
|
||||
mSM.pStats.Traction = 0.01f;
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
//if next state isn't crouch then revert player rotation, height, and traction
|
||||
if(nextState != mSM.CrouchState){
|
||||
mSM.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
|
||||
mSM.pStats.CurVel = mSM.calculatedCurVel;
|
||||
mSM.pStats.Traction = originalTraction;
|
||||
mSM.moveController.height *= 2.0f;
|
||||
}
|
||||
|
||||
//if state is crouch revert traction
|
||||
else{
|
||||
mSM.pStats.Traction = originalTraction;
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//if player comes to a stop while sliding they crouch
|
||||
if(mSM.calculatedCurVel < mSM.idleLimit){
|
||||
mSM.SwitchState(mSM.CrouchState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
//counter rotates player so they don't rotate when camera is turned
|
||||
mSM.transform.Rotate(Vector3.forward * -mSM.sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
|
||||
|
||||
//steadily increase traction
|
||||
mSM.pStats.Traction += .004f;
|
||||
|
||||
///////ONCE WE HAVE IT SO SLIDE DOESNT ROTATE PLAYER MOVE THIS TO UPDATE
|
||||
if((!Input.GetKey(KeyCode.JoystickButton1) && !Input.GetKey(KeyCode.Q))){
|
||||
if ((Physics.Raycast(mSM.gameObject.transform.position, mSM.slideUp, out slideRay, 5f) == false)){
|
||||
|
||||
//Determine which state to go into based on player speed
|
||||
if(mSM.calculatedCurVel < mSM.walkLimit){
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
else if(mSM.calculatedCurVel < mSM.runLimit){
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
else{
|
||||
mSM.SwitchState(mSM.RunState);
|
||||
}
|
||||
}
|
||||
else{
|
||||
Debug.Log("Object above you");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
//If falling stop sliding and go to wasd states
|
||||
if(mSM.aSM.currentState == mSM.aSM.FallingState){
|
||||
//Determine which state to go into based on player speed
|
||||
if(mSM.calculatedCurVel < mSM.walkLimit){
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
else if(mSM.calculatedCurVel < mSM.runLimit){
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
else{
|
||||
SlideToMoveState(mSM);
|
||||
mSM.SwitchState(mSM.RunState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//actual slide movement
|
||||
mSM.SlideMovement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97a1f49e89c304c40a6cb668ea8d8de4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 094431cb9d3653a43992b9dc8a0103d1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveIdleState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//Move to Walk State after speed increases
|
||||
if(mSM.calculatedCurVel >= mSM.idleLimit){
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
|
||||
//If Q or joystick button1 crouch state
|
||||
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
|
||||
mSM.SwitchState(mSM.CrouchState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
//actual directional movement
|
||||
mSM.DirectionalMovement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d01001f0372d1c47a52e1fc1f304d2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveJogState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//move to run state if speed increases
|
||||
if(mSM.calculatedCurVel >= mSM.runLimit){
|
||||
mSM.SwitchState(mSM.RunState);
|
||||
}
|
||||
//move to walk if speed decreases
|
||||
else if(mSM.calculatedCurVel < mSM.walkLimit){
|
||||
mSM.SwitchState(mSM.WalkState);
|
||||
}
|
||||
|
||||
//move to slide if Q or JoystickButton1
|
||||
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
|
||||
mSM.SwitchState(mSM.SlideState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
|
||||
//actual directional movment
|
||||
mSM.DirectionalMovement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8c43483291311242a8bfaaeb5a7728c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveRunState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//move to Jog if speed decreases
|
||||
if(mSM.calculatedCurVel < mSM.runLimit){
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
|
||||
//move to slide if Q or JoystickButton1
|
||||
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
|
||||
mSM.SwitchState(mSM.SlideState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
//actual direction movement
|
||||
mSM.DirectionalMovement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e0d2cf4d9d69a749a2df71f0c77f78c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dMoveWalkState : dMoveBaseState
|
||||
{
|
||||
public override void EnterState(dMoveStateManager mSM, dMoveBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dMoveStateManager mSM, dMoveBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dMoveStateManager mSM){
|
||||
|
||||
//move to Jog if speed increases
|
||||
if(mSM.calculatedCurVel >= mSM.jogLimit){
|
||||
mSM.SwitchState(mSM.JogState);
|
||||
}
|
||||
//move to Idle if speed decreases
|
||||
else if(mSM.calculatedCurVel < mSM.idleLimit){
|
||||
mSM.SwitchState(mSM.IdleState);
|
||||
}
|
||||
|
||||
//move to slide if Q or JoystickButton1
|
||||
else if((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)) && (mSM.aSM.currentState != mSM.aSM.FallingState && mSM.aSM.currentState != mSM.aSM.WallRunState && mSM.aSM.currentState != mSM.aSM.WallIdleState && mSM.aSM.currentState != mSM.aSM.GrappleGroundedState)){
|
||||
mSM.SwitchState(mSM.SlideState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dMoveStateManager mSM){
|
||||
//actual directional movemnt
|
||||
mSM.DirectionalMovement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 158973e7b7bff7843977ff34ddea87f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class dMoveBaseState
|
||||
{
|
||||
public abstract void EnterState(dMoveStateManager mSM, dMoveBaseState previousState);
|
||||
public abstract void ExitState(dMoveStateManager mSM, dMoveBaseState nextState);
|
||||
public abstract void UpdateState(dMoveStateManager mSM);
|
||||
public abstract void FixedUpdateState(dMoveStateManager mSM);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04e8eb3bf333b6446ace02183df6dc52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,276 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
|
||||
public class dMoveStateManager : NetworkBehaviour
|
||||
{
|
||||
////Player States
|
||||
public dMoveBaseState currentState;
|
||||
public dMoveBaseState previousState;
|
||||
|
||||
//WASD States
|
||||
public dMoveIdleState IdleState = new dMoveIdleState();
|
||||
public dMoveWalkState WalkState = new dMoveWalkState();
|
||||
public dMoveJogState JogState = new dMoveJogState();
|
||||
public dMoveRunState RunState = new dMoveRunState();
|
||||
|
||||
//Slide States
|
||||
public dMoveSlideState SlideState = new dMoveSlideState();
|
||||
public dMoveCrouchState CrouchState = new dMoveCrouchState();
|
||||
public dMoveCrouchWalkState CrouchWalkState = new dMoveCrouchWalkState();
|
||||
|
||||
//Incapitated States
|
||||
public dMoveRagdollState RagdollState = new dMoveRagdollState();
|
||||
public dMoveRecoveringState RecoveringState = new dMoveRecoveringState();
|
||||
|
||||
//Grapple States
|
||||
public dMoveGrappleAirState GrappleAirState = new dMoveGrappleAirState();
|
||||
////
|
||||
|
||||
////Objects Sections
|
||||
private GameObject parentObj; // Parent object
|
||||
public Camera cam; // Camera object
|
||||
////
|
||||
|
||||
////Components Section
|
||||
public CharacterController moveController; // Character Controller
|
||||
public Rigidbody rB; // Players Rigidbody
|
||||
public CapsuleCollider capCol; // Players Capsule Collider
|
||||
private Animator animator; // Animation Controller
|
||||
////
|
||||
|
||||
////Scripts Section
|
||||
public PlayerStats pStats; // Player Stats
|
||||
public dAerialStateManager aSM;
|
||||
////
|
||||
|
||||
////State Transition Variables
|
||||
public float idleLimit = .3f;
|
||||
public float walkLimit = 10.0f;
|
||||
public float jogLimit = 20f;
|
||||
public float runLimit = 30f;
|
||||
////
|
||||
|
||||
////Player Variables Section
|
||||
//Speed Variables
|
||||
public Vector3 vel; // moveZ + moveX
|
||||
private Vector3 moveZ; // Local Horizontal Vector
|
||||
private Vector3 moveX; // Local Vertical Vector
|
||||
public Vector3 driftVel; // Lerped Movement Vector
|
||||
public float calculatedCurVel; // calculated current vel using driftVel
|
||||
|
||||
//Slide Variables
|
||||
public Vector3 slideUp; // Slide upwards direction
|
||||
|
||||
//Camera Variables
|
||||
private Vector3 camRotation; // cameras camera rotation vector
|
||||
[Range(-45, -15)]
|
||||
public int minAngle = -18; // minimum downwards cam angle
|
||||
[Range(30, 80)]
|
||||
public int maxAngle = 30; // Max upwards cam angle
|
||||
[Range(50, 500)]
|
||||
public int sensitivity = 200; // Camera sensitivity
|
||||
|
||||
//Ragdoll Variables
|
||||
public Vector3 dirHit; // Direction hit
|
||||
public float distToGround; // distance to ground
|
||||
////
|
||||
|
||||
|
||||
void Awake(){
|
||||
|
||||
////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
|
||||
////
|
||||
|
||||
////Initialize Scripts
|
||||
pStats = GetComponent<PlayerStats>(); // set PlayerStats
|
||||
aSM = GetComponent<dAerialStateManager>(); // aerial state manager
|
||||
////
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
//players starting state
|
||||
currentState = IdleState;
|
||||
previousState = IdleState;
|
||||
currentState.EnterState(this, previousState);
|
||||
|
||||
//Slide Upwards Variable
|
||||
slideUp = GetComponentInParent<Transform>().up; // get parents up direction
|
||||
distToGround = GetComponent<Collider>().bounds.extents.y; // set players distance to ground
|
||||
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
Cursor.lockState = CursorLockMode.Locked; // Lock cursor on start if you are the local player
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
//calculates vel using driftVel will need to be relocated
|
||||
calculatedCurVel = driftVel.magnitude * 50f;
|
||||
|
||||
//if grappling in aerial state manager swap to grapple here
|
||||
if(currentState != GrappleAirState){
|
||||
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != RagdollState && currentState != RecoveringState)){
|
||||
SwitchState(GrappleAirState);
|
||||
}
|
||||
}
|
||||
|
||||
//calls any logic in the update state from current state
|
||||
currentState.UpdateState(this);
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
|
||||
//if camera is enabled then rotate
|
||||
if(cam.enabled) Rotation();
|
||||
else Debug.Log("Cam Disabled");
|
||||
|
||||
//calls any logic in the fixed update state from current state
|
||||
currentState.FixedUpdateState(this);
|
||||
}
|
||||
|
||||
public void SwitchState(dMoveBaseState 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);
|
||||
}
|
||||
|
||||
|
||||
////Broad Functions
|
||||
//Player Speed Calculator
|
||||
public float PlayerSpeed(){
|
||||
//If nothing is pressed speed is 0
|
||||
if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f))
|
||||
{
|
||||
pStats.CurVel = 0.0f;
|
||||
return pStats.CurVel;
|
||||
}
|
||||
//If current speed is below min when pressed set to minimum speed
|
||||
else if (pStats.CurVel < pStats.MinVel)
|
||||
{
|
||||
pStats.CurVel = pStats.MinVel;
|
||||
return pStats.MinVel;
|
||||
}
|
||||
// while the speed is below max speed slowly increase it
|
||||
else if ((pStats.CurVel >= pStats.MinVel) && (pStats.CurVel < pStats.MaxVel))
|
||||
{
|
||||
pStats.CurVel += pStats.Acc;
|
||||
return pStats.CurVel;
|
||||
}
|
||||
//If the players speed is above or equal to max speed set speed to max
|
||||
else if (pStats.CurVel >= pStats.MaxVel)
|
||||
{
|
||||
pStats.CurVel = pStats.MaxVel;
|
||||
return pStats.CurVel;
|
||||
|
||||
}
|
||||
//case if somehow they escape this check
|
||||
else{
|
||||
Debug.Log("Something has gone wrong with the PlayerSpeed()");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//Wasd movement using player speed
|
||||
public void DirectionalMovement(){
|
||||
//Keyboard inputs
|
||||
//Checks if movement keys have been pressed and calculates correct vector
|
||||
moveX = transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * PlayerSpeed();
|
||||
moveZ = transform.forward * Input.GetAxis("Vertical") * Time.deltaTime * PlayerSpeed();
|
||||
|
||||
vel = moveX + moveZ;
|
||||
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
|
||||
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.Traction * Time.deltaTime);
|
||||
if(currentState == GrappleAirState){
|
||||
driftVel = Vector3.zero;
|
||||
}
|
||||
|
||||
//Actually move he player
|
||||
moveController.Move(driftVel);
|
||||
}
|
||||
|
||||
//Slide movement
|
||||
public void SlideMovement(){
|
||||
|
||||
moveX = Vector3.zero;
|
||||
moveZ = Vector3.zero;
|
||||
|
||||
//Adds vectors based on movement keys and other conditions to check what the
|
||||
//player vector should be under the circumstances
|
||||
vel = moveX + moveZ;
|
||||
Vector3 moveXZ = new Vector3(vel.x, 0, vel.z);
|
||||
driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.Traction * Time.deltaTime);
|
||||
|
||||
//Actually move he player
|
||||
moveController.Move(driftVel);
|
||||
}
|
||||
|
||||
//Camera and player rotation
|
||||
private void Rotation(){
|
||||
//If moveController is enabled allow Camera control
|
||||
if(moveController.enabled){
|
||||
//if input is received from Mouse X
|
||||
if (Input.GetAxis("Mouse X") != 0){
|
||||
transform.parent.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
|
||||
}
|
||||
|
||||
//if input is received from right analog stick (horizontal)
|
||||
else if(Input.GetAxis("HorizontalCam") != 0){
|
||||
transform.parent.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("HorizontalCam"));
|
||||
}
|
||||
|
||||
//if input is if input is received from Mouse Y
|
||||
if (Input.GetAxis("Mouse Y") != 0)
|
||||
{
|
||||
camRotation.x -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
|
||||
camRotation.x = Mathf.Clamp(camRotation.x, minAngle, maxAngle);
|
||||
cam.transform.localEulerAngles = camRotation;
|
||||
}
|
||||
|
||||
//if input is received from right analog stick (vertical)
|
||||
else if (Input.GetAxis("VerticalTurn") != 0){
|
||||
camRotation.x -= Input.GetAxis("VerticalTurn") * sensitivity * Time.deltaTime;
|
||||
camRotation.x = Mathf.Clamp(camRotation.x, minAngle, maxAngle);
|
||||
cam.transform.localEulerAngles = camRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Get hit into a ragdoll
|
||||
public void GetHit(Vector3 dir, float force){
|
||||
//if (!IsLocalPlayer) { return; }
|
||||
dir.Normalize();
|
||||
dirHit = dir * force;
|
||||
SwitchState(RagdollState);
|
||||
}
|
||||
|
||||
//remove player momentum
|
||||
public void CancelMomentum(){
|
||||
pStats.CurVel = 0;
|
||||
vel = Vector3.zero;
|
||||
moveX = Vector3.zero;
|
||||
moveZ = Vector3.zero;
|
||||
driftVel = Vector3.zero;
|
||||
}
|
||||
////
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e5dfab4fa1cb9547a860b23f54e51f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e45fd7b4c1454174b8550c7972e492cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b01e94869f67a4b419906fd52ad3bd4c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dNitroCooldownState : dNitroBaseState
|
||||
{
|
||||
bool cooldown = false; // whether or not cooldown has ended
|
||||
|
||||
public override void EnterState(dNitroStateManager nSM, dNitroBaseState previousState){
|
||||
cooldown = false; // cooldown hasn't ended
|
||||
|
||||
//start cooldown
|
||||
nSM.StartCoroutine(startCoolDown(nSM));
|
||||
}
|
||||
|
||||
public override void ExitState(dNitroStateManager nSM, dNitroBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dNitroStateManager nSM){
|
||||
|
||||
//if off cooldown and incapacitated then incapacitated
|
||||
if(cooldown && (nSM.mSM.currentState == nSM.mSM.RagdollState || nSM.mSM.currentState == nSM.mSM.RecoveringState)){
|
||||
nSM.SwitchState(nSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if off cooldown then None
|
||||
else if(cooldown){
|
||||
nSM.SwitchState(nSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dNitroStateManager nSM){
|
||||
|
||||
}
|
||||
|
||||
//cooldown timer
|
||||
private IEnumerator startCoolDown(dNitroStateManager nSM){
|
||||
//nSM.driver.startUICooldown("Nitro");
|
||||
yield return new WaitForSeconds(nSM.nitroItem.cooldownM);
|
||||
cooldown = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fb7f3ef3c9577f4287b92706af55e2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dNitroIncapacitatedState : dNitroBaseState
|
||||
{
|
||||
public override void EnterState(dNitroStateManager nSM, dNitroBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dNitroStateManager nSM, dNitroBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dNitroStateManager nSM){
|
||||
|
||||
//if no longer incapacitated then None
|
||||
if(nSM.mSM.currentState != nSM.mSM.RagdollState && nSM.mSM.currentState != nSM.mSM.RecoveringState){
|
||||
nSM.SwitchState(nSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dNitroStateManager nSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1508acc725507574c8ed912792441f18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dNitroNitroingState : dNitroBaseState
|
||||
{
|
||||
|
||||
private float tempTimer; // temporary timer
|
||||
private float actualMaxVel; // actual max velocity
|
||||
private float actualAcc; // actual acceleration
|
||||
|
||||
public override void EnterState(dNitroStateManager nSM, dNitroBaseState previousState){
|
||||
actualMaxVel = nSM.pStats.MaxVel; // saves previous max velocity
|
||||
actualAcc = nSM.pStats.Acc; // saves previous max acc
|
||||
nSM.pStats.Acc += nSM.nitroAccBoost; // increases acceleration
|
||||
nSM.pStats.MaxVel += nSM.nitroVelBoost; // increases max velocity
|
||||
|
||||
tempTimer = 5; // how long we will be sped up
|
||||
}
|
||||
|
||||
public override void ExitState(dNitroStateManager nSM, dNitroBaseState nextState){
|
||||
nSM.pStats.Acc = actualAcc; // reset acceleration
|
||||
nSM.pStats.MaxVel = actualMaxVel; // reset maximum velocity
|
||||
}
|
||||
|
||||
public override void UpdateState(dNitroStateManager nSM){
|
||||
|
||||
//if still nitroing decrease timer
|
||||
if(tempTimer > 0){
|
||||
tempTimer -= .02f;
|
||||
}
|
||||
|
||||
//otherwise cooldown
|
||||
else{
|
||||
nSM.SwitchState(nSM.CooldownState);
|
||||
}
|
||||
|
||||
//if ragdolling then cooldown
|
||||
if(nSM.mSM.currentState == nSM.mSM.RagdollState){
|
||||
nSM.SwitchState(nSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dNitroStateManager nSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a43417b0cdae78446b79108e34bbf903
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dNitroNoneState : dNitroBaseState
|
||||
{
|
||||
public override void EnterState(dNitroStateManager nSM, dNitroBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dNitroStateManager nSM, dNitroBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dNitroStateManager nSM){
|
||||
|
||||
//if player has nitro
|
||||
if(nSM.pStats.HasNitro){
|
||||
|
||||
//if ragdolling then incapacitiated
|
||||
if(nSM.mSM.currentState == nSM.mSM.RagdollState){
|
||||
nSM.SwitchState(nSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if pressing left shift then nitroing
|
||||
else if ((Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.JoystickButton8)))
|
||||
{
|
||||
nSM.SwitchState(nSM.NitroingState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dNitroStateManager nSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62a4ada9bb0dd0a43b2218ddcb3a71f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class dNitroBaseState
|
||||
{
|
||||
public abstract void EnterState(dNitroStateManager nSM, dNitroBaseState previousState);
|
||||
public abstract void ExitState(dNitroStateManager nSM, dNitroBaseState nextState);
|
||||
public abstract void UpdateState(dNitroStateManager nSM);
|
||||
public abstract void FixedUpdateState(dNitroStateManager nSM);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0695391761689164ca7276b45f57ece3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
|
||||
public class dNitroStateManager : NetworkBehaviour
|
||||
{
|
||||
////Player States
|
||||
public dNitroBaseState currentState;
|
||||
public dNitroBaseState previousState;
|
||||
|
||||
//Nitro States
|
||||
public dNitroNoneState NoneState = new dNitroNoneState();
|
||||
public dNitroIncapacitatedState IncapacitatedState = new dNitroIncapacitatedState();
|
||||
public dNitroCooldownState CooldownState = new dNitroCooldownState();
|
||||
public dNitroNitroingState NitroingState = new dNitroNitroingState();
|
||||
////
|
||||
|
||||
////Objects Sections
|
||||
GameObject parentObj; // Parent object
|
||||
////
|
||||
|
||||
////Components Section
|
||||
public CharacterController moveController; // Character Controller
|
||||
Rigidbody rB; // Players Rigidbody
|
||||
CapsuleCollider capCol; // Players Capsule Collider
|
||||
Animator animator; // Animation Controller
|
||||
////
|
||||
|
||||
////Scripts Section
|
||||
public PlayerStats pStats; // Player Stats
|
||||
public dMoveStateManager mSM; // move state manager
|
||||
public CoolDown driver; // cooldown driver
|
||||
////
|
||||
|
||||
////Items Section
|
||||
public SpecialItem nitroItem; // nitro item
|
||||
////
|
||||
|
||||
////Variables Section
|
||||
public float nitroVelBoost = 40;
|
||||
public float nitroAccBoost = .4f;
|
||||
|
||||
void Awake(){
|
||||
|
||||
////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
|
||||
//driver = GameObject.Find("Canvas").GetComponent<CoolDown>();
|
||||
////
|
||||
|
||||
////Initialize Scripts
|
||||
pStats = GetComponent<PlayerStats>(); // set PlayerStats
|
||||
mSM = GetComponent<dMoveStateManager>(); // set move state manager
|
||||
////
|
||||
}
|
||||
|
||||
void Start(){
|
||||
//players starting state
|
||||
currentState = NoneState;
|
||||
previousState = NoneState;
|
||||
currentState.EnterState(this, previousState);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void SwitchState(dNitroBaseState 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 455a2b894b8cfef4bab705dde1a6784b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 780d9208d30e9c6459ae00ff49272e51
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbd26ea59a5c21a4284c123c05406717
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffenseAirKickState : dOffenseBaseState
|
||||
{
|
||||
|
||||
private float legRotation = 0; // angle for leg rotation
|
||||
bool kicked = false; // whether they have kicked or not
|
||||
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
oSM.leg.SetActive(true); // activate leg
|
||||
legRotation = -90;
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
kicked = false; // haven't kicked
|
||||
|
||||
//start kicking routine
|
||||
oSM.StartCoroutine(kicking(8f));
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
legRotation = 0; // reset leg angle
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
oSM.leg.SetActive(false); // reset leg angle
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if incapacitated then cooldown
|
||||
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
|
||||
//if kicked or grounded then cooldown
|
||||
if(kicked || (oSM.aSM.currentState == oSM.aSM.GroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//jitter player upwards because of a weird issue with collider
|
||||
oSM.moveController.Move(new Vector3(0,.002f,0));
|
||||
}
|
||||
|
||||
//kicking timer
|
||||
private IEnumerator kicking(float waitTime){
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
kicked = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1979beb1f8855ca419e5694da5cd0c26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffenseAirPunchState : dOffenseBaseState
|
||||
{
|
||||
|
||||
private float legRotation = 0; // angle for leg rotation
|
||||
bool kicked = false; // whether they have kicked or not
|
||||
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
oSM.leg.SetActive(true); // activate leg
|
||||
legRotation = -90;
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
kicked = false; // haven't kicked
|
||||
|
||||
//start kicking routine
|
||||
oSM.StartCoroutine(kicking(8f));
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
legRotation = 0; // reset leg angle
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
oSM.leg.SetActive(false); // reset leg angle
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if incapacitated then cooldown
|
||||
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
|
||||
//if kicked or grounded then cooldown
|
||||
if(kicked || (oSM.aSM.currentState == oSM.aSM.GroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//jitter player upwards because of a weird issue with collider
|
||||
oSM.moveController.Move(new Vector3(0,.002f,0));
|
||||
}
|
||||
|
||||
//kicking timer
|
||||
private IEnumerator kicking(float waitTime){
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
kicked = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 639f429564de9864292274ce4630d8b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffenseKickState : dOffenseBaseState
|
||||
{
|
||||
|
||||
float legRotation = 0; // angle for leg rotation
|
||||
bool kicked = false; // whether they have kicked or not
|
||||
|
||||
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
oSM.leg.SetActive(true); // activate leg
|
||||
kicked = false; // haven't kicked
|
||||
|
||||
//start kicking routine
|
||||
oSM.StartCoroutine(kicking(1f));
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
legRotation = 0; // reset leg angle
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
oSM.leg.SetActive(false); // reset leg angle
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if incapacitated then cooldown
|
||||
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
|
||||
//if kicked then cooldown
|
||||
if(kicked){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if leg isn't fully extended rotate it
|
||||
if(legRotation > -90){
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
|
||||
legRotation -= 20;
|
||||
}
|
||||
else{
|
||||
legRotation = -90;
|
||||
}
|
||||
|
||||
//jitter player upwards because of a weird issue with collider
|
||||
oSM.moveController.Move(new Vector3(0,.002f,0));
|
||||
}
|
||||
|
||||
//kicking timer
|
||||
private IEnumerator kicking(float waitTime){
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
kicked = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b4d338e2fa79844b8a2a385e9534520
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffensePunchState : dOffenseBaseState
|
||||
{
|
||||
|
||||
float legRotation = 0; // angle for leg rotation
|
||||
bool kicked = false; // whether they have kicked or not
|
||||
|
||||
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
oSM.leg.SetActive(true); // activate leg
|
||||
kicked = false; // haven't kicked
|
||||
|
||||
//start kicking routine
|
||||
oSM.StartCoroutine(kicking(1f));
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
legRotation = 0; // reset leg angle
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z); // rotate leg
|
||||
oSM.leg.SetActive(false); // deactivate leg
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if incapacitated then cooldown
|
||||
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
|
||||
//if kicked then cooldown
|
||||
if(kicked){
|
||||
oSM.SwitchState(oSM.CooldownState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if leg isn't fully extended rotate it
|
||||
if(legRotation > -90){
|
||||
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
|
||||
legRotation -= 20;
|
||||
}
|
||||
else{
|
||||
legRotation = -90;
|
||||
}
|
||||
|
||||
//jitter player upwards because of a weird issue with collider
|
||||
oSM.moveController.Move(new Vector3(0,.002f,0));
|
||||
}
|
||||
|
||||
//kicking timer
|
||||
private IEnumerator kicking(float waitTime){
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
kicked = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 190b69b70a6fd684aabaee22d13b1d41
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b4008d8f961aaa4cac36f186b176641
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffenseCooldownState : dOffenseBaseState
|
||||
{
|
||||
bool cooldown = false; // whether or not cooldown is over
|
||||
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
cooldown = false; // cooldown isn't over
|
||||
|
||||
//start cooldown
|
||||
oSM.StartCoroutine(kickCooldown());
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if cooldown over and incapacitated then incapacitated
|
||||
if(cooldown && (oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if cooldown over then None
|
||||
else if(cooldown){
|
||||
oSM.SwitchState(oSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
}
|
||||
|
||||
//kick cooldown
|
||||
private IEnumerator kickCooldown(){
|
||||
yield return new WaitForSeconds(.5f);
|
||||
cooldown = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6057e16fd22e5bc4893db0d4392988d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class dOffenseIncapacitatedState : dOffenseBaseState
|
||||
{
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if no longer incapacitated then None
|
||||
if((oSM.mSM.currentState != oSM.mSM.RagdollState && oSM.mSM.currentState != oSM.mSM.SlideState && oSM.mSM.currentState != oSM.mSM.CrouchState && oSM.mSM.currentState != oSM.mSM.CrouchWalkState) && (oSM.aSM.currentState != oSM.aSM.WallRunState && oSM.aSM.currentState != oSM.aSM.WallIdleState && oSM.aSM.currentState != oSM.aSM.GrappleAirState && oSM.aSM.currentState != oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.NoneState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a65473cdff4d4d343bd9fea0d2abf01b
|
||||
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 dOffenseNoneState : dOffenseBaseState
|
||||
{
|
||||
public override void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState){
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState){
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateState(dOffenseStateManager oSM){
|
||||
|
||||
//if incapacitated then incapacitated
|
||||
if((oSM.mSM.currentState == oSM.mSM.RagdollState || oSM.mSM.currentState == oSM.mSM.SlideState || oSM.mSM.currentState == oSM.mSM.CrouchState || oSM.mSM.currentState == oSM.mSM.CrouchWalkState) || (oSM.aSM.currentState == oSM.aSM.WallRunState || oSM.aSM.currentState == oSM.aSM.WallIdleState || oSM.aSM.currentState == oSM.aSM.GrappleAirState || oSM.aSM.currentState == oSM.aSM.GrappleGroundedState)){
|
||||
oSM.SwitchState(oSM.IncapacitatedState);
|
||||
}
|
||||
|
||||
//if grounded then grounded kick states
|
||||
else if(oSM.aSM.currentState == oSM.aSM.GroundedState && (Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0)){
|
||||
|
||||
//if power is above 300 then punch
|
||||
if(oSM.pStats.KickPow > 300){
|
||||
oSM.SwitchState(oSM.PunchState);
|
||||
}
|
||||
|
||||
//otherwise kick
|
||||
else{
|
||||
oSM.SwitchState(oSM.KickState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//if in the air
|
||||
else if((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0)){
|
||||
|
||||
//if power is above 300 air punch
|
||||
if(oSM.pStats.KickPow > 300){
|
||||
oSM.SwitchState(oSM.AirPunchState);
|
||||
}
|
||||
|
||||
//otherwise air kick
|
||||
else{
|
||||
oSM.SwitchState(oSM.AirKickState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixedUpdateState(dOffenseStateManager oSM){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 207ecd38b476de8458c6f495c74f01c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class dOffenseBaseState
|
||||
{
|
||||
public abstract void EnterState(dOffenseStateManager oSM, dOffenseBaseState previousState);
|
||||
public abstract void ExitState(dOffenseStateManager oSM, dOffenseBaseState nextState);
|
||||
public abstract void UpdateState(dOffenseStateManager oSM);
|
||||
public abstract void FixedUpdateState(dOffenseStateManager oSM);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48e9373052af5ca40b2f91cfb88cd315
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user