created a debug prefab

This commit is contained in:
Melbyj1125
2022-02-18 13:56:10 -06:00
parent 820b11dd61
commit 167f7840a0
108 changed files with 9076 additions and 123 deletions

View File

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

View File

@@ -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();
}
}

View File

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

View File

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

View File

@@ -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);
}
}
}

View File

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

View File

@@ -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){
}
}

View File

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

View File

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

View File

@@ -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);
}
*/
}
}

View File

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

View File

@@ -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);
}
}
*/
}
}

View File

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

View File

@@ -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();
}
}

View File

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

View File

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

View File

@@ -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();
}
}

View File

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

View File

@@ -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();
}
}

View File

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

View File

@@ -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();
}
}

View File

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

View File

@@ -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();
}
}

View File

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

View File

@@ -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);
}

View File

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

View File

@@ -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;
}
////
}

View File

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