Did some bugfixing and commented on everything

This commit is contained in:
Melbyj1125 2022-02-17 20:55:23 -06:00
parent e74a1c61c0
commit 820b11dd61
40 changed files with 528 additions and 250 deletions

View File

@ -4743,12 +4743,11 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7688428083034862386}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 201caa2b2f1776a46af6bdfd52456028, type: 3}
m_Name:
m_EditorClassIdentifier:
cam: {fileID: 8193413098731078861}
moveController: {fileID: 0}
pStats: {fileID: 0}
mSM: {fileID: 0}
@ -4761,12 +4760,12 @@ MonoBehaviour:
isGrounded: 0
groundCheckDistance: 0.05
isWallRunning: 0
maxGrabDistance: 30
maxGrabDistance: 50
hookPoint: {fileID: 0}
hookPoints: []
hookPointIndex: 0
distance: 0
maxGrappleDistance: 20
maxGrappleDistance: 25
maxSwingSpeed: 50
minSwingSpeed: 20
swingAcc: 3

View File

@ -2715,7 +2715,7 @@ Transform:
m_LocalScale: {x: 10, y: 10, z: 10}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1781357367
GameObject:
@ -2907,6 +2907,67 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1806935633}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1935079347
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_RootOrder
value: 9
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 297879044457584256, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3039877022422189067, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_Name
value: DebugPlayerPrefab 1
objectReference: {fileID: 0}
- target: {fileID: 3039877022422189067, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3}
--- !u!1 &1985880502
GameObject:
m_ObjectHideFlags: 0
@ -3044,9 +3105,13 @@ PrefabInstance:
propertyPath: m_Name
value: NetworkSMPlayerPrefab
objectReference: {fileID: 0}
- target: {fileID: 2080873442886702253, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3669633515805984294, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_RootOrder
value: 10
value: 11
objectReference: {fileID: 0}
- target: {fileID: 3669633515805984294, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_LocalPosition.x
@ -3088,5 +3153,45 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862280, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862287, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: hasGrapple
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862387, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862389, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862390, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7688428083034862391, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8193413098731078848, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8193413098731078861, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8193413098731078862, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8193413098731078863, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1e178f956ddfe5143b2b9e77e76db7f0, type: 3}

View File

@ -15,26 +15,27 @@ public class AerialFallingState : AerialBaseState
public override void UpdateState(AerialStateManager aSM){
//if Grav Vel > 0 then jumping
if(aSM.pStats.GravVel > 0){
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
if(aSM.isGrounded){
else if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
//if is wallrunning ands is in a state that allows it wallrun
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
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
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
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);
}
}

View File

@ -22,22 +22,22 @@ public class AerialGlidingState : AerialBaseState
public override void UpdateState(AerialStateManager aSM){
//if not holding jump fall
if(!Input.GetButton("Jump")){
if(!Input.GetButton("Jump") || (aSM.mSM.currentState == aSM.mSM.RagdollState)){
aSM.SwitchState(aSM.FallingState);
}
//if is grounded then grounded
if(aSM.isGrounded){
else if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
//if isWallrunning and in state that allows it wallrun
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
else if(aSM.isWallRunning){
aSM.SwitchState(aSM.WallRunState);
}
//if can grapple and in state that allows it grapple
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
else if(aSM.CheckGrapple()){
aSM.SwitchState(aSM.GrappleAirState);
}
}

View File

@ -17,16 +17,16 @@ public class AerialGroundedState : AerialBaseState
public override void UpdateState(AerialStateManager aSM){
//if grav vel < 0 then falling
if(aSM.pStats.GravVel < 0){
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){
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
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
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);
}
}

View File

@ -16,22 +16,22 @@ public class AerialJumpingState : AerialBaseState
public override void UpdateState(AerialStateManager aSM){
//if grav vel < 0 falling
if(aSM.pStats.GravVel < 0){
if(aSM.pStats.GravVel < 0 || aSM.mSM.currentState == aSM.mSM.RagdollState){
aSM.SwitchState(aSM.FallingState);
}
//if is grounded then grounded
if(aSM.isGrounded){
else if(aSM.isGrounded){
aSM.SwitchState(aSM.GroundedState);
}
//if is wall running and in a state that allows it wallrun
if(aSM.isWallRunning && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
else if(aSM.isWallRunning){
aSM.SwitchState(aSM.WallRunState);
}
//if can grapple and in a state that allows it grapple
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
else if(aSM.CheckGrapple()){
aSM.SwitchState(aSM.GrappleAirState);
}
}

View File

@ -28,13 +28,11 @@ public class AerialStateManager : NetworkBehaviour
////Objects Sections
GameObject parentObj; // Parent object
public Camera cam; // Camera object
////
////Components Section
public CharacterController moveController; // Character Controller
Rigidbody rB; // Players Rigidbody
CapsuleCollider capCol; // Players Capsule Collider
Animator animator; // Animation Controller
////
@ -65,43 +63,42 @@ public class AerialStateManager : NetworkBehaviour
RaycastHit groundHit; // ground raycast
//Wallrun
float wallMaxDistance = 3f;
float wallSpeedMultiplier = 1.5f;
float minimumHeight = .1f;
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;
float jumpDuration = .02f;
float wallBouncing = 3;
Vector3[] directions;
RaycastHit[] hits;
public bool isWallRunning = false;
Vector3 lastWallPosition;
Vector3 lastWallNormal;
float elapsedTimeSinceJump = 0;
float elapsedTimeSinceWallAttach = 0;
float elapsedTimeSinceWallDetatch = 0;
bool jumping;
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 = 30;// Max Distance can cast grapple
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 = 20; // Max Rope Length
public float maxSwingSpeed = 50;
public float minSwingSpeed = 20;
public float swingAcc = 3f;
public float maxSwingMom = 60;
public bool release = false;
public Vector3 tempRelease;
public Vector3 lerpRelease;
public Vector3 forceDirection;
public bool eHeld;
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(){
@ -109,8 +106,6 @@ public class AerialStateManager : NetworkBehaviour
////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
////
@ -156,11 +151,20 @@ public class AerialStateManager : NetworkBehaviour
//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();
}
@ -168,7 +172,9 @@ public class AerialStateManager : NetworkBehaviour
//Dissipates Impact
DissipateImpact();
}
else{
//Gravity without moveController
pStats.GravVel -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,pStats.GravVel,0));
@ -499,6 +505,7 @@ public class AerialStateManager : NetworkBehaviour
return index;
}
//lerped grapple release force and dissipation of it
public void GrappleReleaseForce(){
if(release){
lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 9f * Time.deltaTime);

View File

@ -4,21 +4,24 @@ using UnityEngine;
public class AerialGrappleAirState : AerialBaseState
{
bool spaceHeld = true;
float ropeLength; // current rope length
Vector3 swingDirection; // Swing direction
float inclinationAngle; // inclination angle
float theta = -1; // theta
float swingMom;
Vector3 tensionMomDirection;
Vector3 hookPointRight;
Vector3 momDirection;
Vector3 curXZDir;
Vector3 oldXZDir;
float swingSpeed = 10;
bool swingback = false; //swing the player back
float oldSwingMom;
Vector3 tensionDirection;
float tensionForce;
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(AerialStateManager aSM, AerialBaseState previousState){
@ -43,48 +46,61 @@ public class AerialGrappleAirState : AerialBaseState
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(AerialStateManager aSM, AerialBaseState nextState){
//If not going into grapple grounded state
if(nextState != aSM.GrappleGroundedState){
aSM.release = true;
aSM.pStats.GravVel = 0;
aSM.forceDirection = Vector3.zero;
swingback = true;
}
//If going into grapple grounded state
else{
aSM.pStats.GravVel = 0;
aSM.forceDirection = Vector3.zero;
swingback = true;
}
}
public override void UpdateState(AerialStateManager aSM){
if((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld){
//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))){
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2)) && aSM.eHeld){
aSM.eHeld = false;
}
if(Input.GetButton("Jump")){
//if pressing Jump then jump
else if(Input.GetButton("Jump") && !spaceHeld){
aSM.SwitchState(aSM.JumpingState);
}
else if(!(Input.GetButton("Jump")) && spaceHeld){
spaceHeld = false;
}
if(aSM.isGrounded){
//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(AerialStateManager 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
//Debug.Log(Vector3.Distance(gameObject.transform.position, hookPoint.transform.position));
//Calculate tether force direction based on hookpoint
if (Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position) >= ropeLength )
{
@ -94,26 +110,23 @@ public class AerialGrappleAirState : AerialBaseState
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();
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
//Needs to be Overhauled to properly implement energy loss taking into account players current Velocity, height and input
//------Important Equations--------
// TensionForce = Cos(theta) * g * m * Vector3(tensionDirection)
// Potential Energy = m * g * h -- Will need to modify adding current speed
// Kinetic Energy = 1/2 * m * V^2 -- assuming no energy loss at the bottom KE = PE at peak we will add energy loss ourselves
// Total Energy = m * ((g*h) + (1/2 * V^2))
// Velocity = (2 * ((TotalEnergy/m) - (g*h)))^(1/2) -- This hypothetically could be used for our swing momentum calculation
// Movement Direction right angle of tension force = Sin(theta) * g * m * Vector3(Right angle to tensionDirection)
//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, AerialStateManager aSM){
@ -129,7 +142,10 @@ public class AerialGrappleAirState : AerialBaseState
//force direction calculation based on tension direction and force
Vector3 fDirection = tensionDirection * tensionForce;
//return force direction
return fDirection;
}
Vector3 CalculateMomentumDirection(float g, Vector3 hPoint, AerialStateManager aSM){
@ -137,23 +153,20 @@ public class AerialGrappleAirState : AerialBaseState
tensionMomDirection = (hPoint - aSM.transform.position).normalized;
hookPointRight = Vector3.Cross(oldXZDir, aSM.transform.up).normalized;
momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized;
if(oldXZDir != curXZDir){
//midpointMom = swingMom;
swingback = false;
//Debug.Log("flip");
}
if(swingback == false && swingMom <= (oldSwingMom*(.75f))){
swingback = true;
//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;
//Debug.Log("swingback");
}
//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
@ -165,11 +178,15 @@ public class AerialGrappleAirState : AerialBaseState
swingHeight = 1;
}
float sMom = playerSpeed + (swingHeight*2);
//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
@ -197,14 +214,12 @@ public class AerialGrappleAirState : AerialBaseState
//Swing direction based on player input
swingDirection = Vector3.Cross(tensionDirection, ((aSM.transform.right * -inputVert) + (aSM.transform.forward * inputHor))).normalized;
//NEED TO ADD SWINGSPEED EASING
//this could be just adding a gradual increase in the swing speed instead of using a flat rate
//Swing movement with swing speed added
Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed);
//returns swing movement vector
return (swingMovement);
}
Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance, AerialStateManager aSM){
@ -215,19 +230,24 @@ public class AerialGrappleAirState : AerialBaseState
//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 < 5){
//if swingMom is low there is no release force
if(swingMom < 2){
return Vector3.zero;
}
//return swing release direction
return releaseSwingForceDirection * Time.deltaTime;
}
}

View File

@ -6,7 +6,8 @@ public class AerialGrappleGroundedState : AerialBaseState
{
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
aSM.release = false;
aSM.release = false; // release is false when grounded
}
public override void ExitState(AerialStateManager aSM, AerialBaseState nextState){
@ -14,25 +15,32 @@ public class AerialGrappleGroundedState : AerialBaseState
}
public override void UpdateState(AerialStateManager aSM){
if(!aSM.isGrounded && aSM.pStats.GravVel < 0){
//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(Vector3.Distance(aSM.transform.position, aSM.hookPoint.transform.position) > aSM.maxGrappleDistance){
//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);
}
if((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && !aSM.eHeld){
aSM.SwitchState(aSM.GroundedState);
}
else if((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.JoystickButton2))){
aSM.eHeld = false;
}
}
public override void FixedUpdateState(AerialStateManager aSM){
Debug.DrawRay(aSM.transform.position, (aSM.hookPoint.transform.position - aSM.transform.position)); //Visual of line
//Default gravity calculation
aSM.GravityCalculation(aSM.pStats.PlayerGrav);
}
}

View File

@ -4,10 +4,12 @@ using UnityEngine;
public class AerialWallRunState : AerialBaseState
{
bool spaceHeld = true;
public override void EnterState(AerialStateManager aSM, AerialBaseState previousState){
aSM.pStats.GravVel = 0;
aSM.pStats.GravVel = 0; // on entering reset grav vel
spaceHeld = true; // prevent accidental wall jumping
}
@ -16,19 +18,31 @@ public class AerialWallRunState : AerialBaseState
}
public override void UpdateState(AerialStateManager aSM){
if(Input.GetButton("Jump")){
//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(!aSM.isWallRunning){
aSM.SwitchState(aSM.FallingState);
else if(!Input.GetButton("Jump") && spaceHeld){
spaceHeld = false;
}
if(aSM.CheckGrapple() && (aSM.mSM.currentState != aSM.mSM.SlideState && aSM.mSM.currentState != aSM.mSM.RagdollState && aSM.mSM.currentState != aSM.mSM.RecoveringState)){
//if able to grapple then grapple
else if(aSM.CheckGrapple()){
aSM.SwitchState(aSM.GrappleAirState);
}
}
public override void FixedUpdateState(AerialStateManager aSM){
//Modified gravity calculation for wallrun
aSM.GravityCalculation(2);
}
}

View File

@ -4,11 +4,11 @@ using UnityEngine;
public class DashCooldownState : DashBaseState
{
bool cooldown = false;
bool cooldown = false; // is cooldown over
public override void EnterState(DashStateManager dSM, DashBaseState previousState){
cooldown = false;
dSM.StartCoroutine(startCoolDown(dSM));
cooldown = false; // sets cooldown
dSM.StartCoroutine(startCoolDown(dSM)); // activates cooldown
}
public override void ExitState(DashStateManager dSM, DashBaseState nextState){
@ -16,9 +16,13 @@ public class DashCooldownState : DashBaseState
}
public override void UpdateState(DashStateManager 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);
}
@ -28,6 +32,7 @@ public class DashCooldownState : DashBaseState
}
//cooldown function
private IEnumerator startCoolDown(DashStateManager dSM){
//dSM.driver.startUICooldown(dashItem.name);
yield return new WaitForSeconds(dSM.dashItem.cooldownM);

View File

@ -5,36 +5,42 @@ using UnityEngine;
public class DashDashingState : DashBaseState
{
Vector3 moveDirection;
const float maxDashTime = 1.0f;
float dashDistance = 10;
float dashStoppingSpeed = 0.1f;
float currentDashTime = maxDashTime;
float dashSpeed = 12;
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(DashStateManager dSM, DashBaseState previousState){
currentDashTime = 0;
currentDashTime = 0; // resets dash time
}
public override void ExitState(DashStateManager dSM, DashBaseState nextState){
moveDirection = Vector3.zero;
moveDirection = Vector3.zero; // resets moveDirection
}
public override void UpdateState(DashStateManager 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(DashStateManager dSM){
//Actually moves the player
dSM.moveController.Move(moveDirection * Time.deltaTime * dashSpeed);
}
}

View File

@ -13,6 +13,8 @@ public class DashIncapacitatedState : DashBaseState
}
public override void UpdateState(DashStateManager 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);
}

View File

@ -13,14 +13,20 @@ public class DashNoneState : DashBaseState
}
public override void UpdateState(DashStateManager dSM){
//checks if player has dash
if(dSM.pStats.HasDash){
if ((Input.GetKeyDown(KeyCode.R) || Input.GetAxis("Dash") != 0)){
//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);
}
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);
}
}
}

View File

@ -15,36 +15,26 @@ public class DashStateManager : NetworkBehaviour
public DashCooldownState CooldownState = new DashCooldownState();
public DashDashingState DashingState = new DashDashingState();
////
////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 MoveStateManager mSM;
public CoolDown driver;
public MoveStateManager mSM; // movement state manager
public CoolDown driver; // cooldown driver
////
////Items Section
public SpecialItem dashItem;
public SpecialItem dashItem; // dash item
////
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>();
////

View File

@ -5,7 +5,7 @@ using UnityEngine;
public class MoveGrappleAirState : MoveBaseState
{
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
mSM.driftVel = Vector3.zero;
mSM.driftVel = Vector3.zero; // clears driftVel
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
@ -13,6 +13,8 @@ public class MoveGrappleAirState : MoveBaseState
}
public override void UpdateState(MoveStateManager 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){
@ -28,7 +30,8 @@ public class MoveGrappleAirState : MoveBaseState
}
public override void FixedUpdateState(MoveStateManager mSM){
//Directional movement to prevent weird movement issue
mSM.DirectionalMovement();
}
}

View File

@ -4,42 +4,51 @@ using UnityEngine;
public class MoveRagdollState : MoveBaseState
{
float ragTime;
Vector3 prevRot;
bool beginRagTimer = false;
float ragTime; // ragdoll timer
Vector3 prevRot; // previous rotation before ragdolled
bool beginRagTimer = false; // whether ragtimer has started
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
ragTime = mSM.pStats.RecovTime;
prevRot = mSM.transform.localEulerAngles;
mSM.capCol.enabled = true;
mSM.moveController.enabled = false;
mSM.rB.isKinematic = false;
mSM.rB.detectCollisions = true;
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(MoveStateManager mSM, MoveBaseState nextState){
mSM.pStats.GravVel = 50;
mSM.capCol.enabled = false;
mSM.moveController.enabled = true;
mSM.rB.isKinematic = true;
mSM.rB.detectCollisions = false;
mSM.transform.localEulerAngles = prevRot;
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(MoveStateManager 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(MoveStateManager mSM){
//Has to be in Fixed Update because it has player movement
//if ragtimer is over then recover
if(ragTime <= 0 && beginRagTimer){
ragTime = 0;
beginRagTimer = false;

View File

@ -7,7 +7,7 @@ public class MoveRecoveringState : MoveBaseState
////// ADD SOMETHING THAT CHECKS ANIMATION FINISH BEFORE GO TO IDLE
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
mSM.CancelMomentum();
mSM.CancelMomentum(); // reset player variables
}
public override void ExitState(MoveStateManager mSM, MoveBaseState nextState){
@ -15,6 +15,8 @@ public class MoveRecoveringState : MoveBaseState
}
public override void UpdateState(MoveStateManager mSM){
//swap to idle state
mSM.SwitchState(mSM.IdleState);
}

View File

@ -66,9 +66,9 @@ public class MoveStateManager : NetworkBehaviour
//Camera Variables
private Vector3 camRotation; // cameras camera rotation vector
[Range(-45, -15)]
public int minAngle = -30; // minimum downwards cam angle
public int minAngle = -18; // minimum downwards cam angle
[Range(30, 80)]
public int maxAngle = 45; // Max upwards cam angle
public int maxAngle = 30; // Max upwards cam angle
[Range(50, 500)]
public int sensitivity = 200; // Camera sensitivity
@ -91,7 +91,7 @@ public class MoveStateManager : NetworkBehaviour
////Initialize Scripts
pStats = GetComponent<PlayerStats>(); // set PlayerStats
aSM = GetComponent<AerialStateManager>();
aSM = GetComponent<AerialStateManager>(); // aerial state manager
////
}
@ -114,12 +114,17 @@ public class MoveStateManager : NetworkBehaviour
// Update is called once per frame
void Update()
{
//if (!IsLocalPlayer) { return; }
if (!IsLocalPlayer) { return; }
//calculates vel using driftVel will need to be relocated
calculatedCurVel = driftVel.magnitude * 50f;
GoToGrapple();
//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);
@ -127,13 +132,14 @@ public class MoveStateManager : NetworkBehaviour
void FixedUpdate(){
//if (!IsLocalPlayer) { return; }
//calls any logic in the fixed update state from current state
currentState.FixedUpdateState(this);
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(MoveBaseState state){
@ -194,6 +200,9 @@ public class MoveStateManager : NetworkBehaviour
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);
@ -246,6 +255,7 @@ public class MoveStateManager : NetworkBehaviour
}
}
//Get hit into a ragdoll
public void GetHit(Vector3 dir, float force){
//if (!IsLocalPlayer) { return; }
dir.Normalize();
@ -253,6 +263,7 @@ public class MoveStateManager : NetworkBehaviour
SwitchState(RagdollState);
}
//remove player momentum
public void CancelMomentum(){
pStats.CurVel = 0;
vel = Vector3.zero;
@ -260,10 +271,6 @@ public class MoveStateManager : NetworkBehaviour
moveZ = Vector3.zero;
driftVel = Vector3.zero;
}
////
void GoToGrapple(){
if(aSM.currentState == aSM.GrappleAirState && (currentState != SlideState && currentState != RagdollState && currentState != RecoveringState)){
SwitchState(GrappleAirState);
}
}
}

View File

@ -10,8 +10,8 @@ public class MoveCrouchState : MoveBaseState
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
//if not coming from slide state then rotate player and adjust height
if(previousState != mSM.SlideState){
//Initialize Important Stats On state enter
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;
@ -19,6 +19,8 @@ public class MoveCrouchState : MoveBaseState
}
public override void ExitState(MoveStateManager mSM, MoveBaseState 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;

View File

@ -10,7 +10,7 @@ public class MoveSlideState : MoveBaseState
public override void EnterState(MoveStateManager mSM, MoveBaseState previousState){
//Initialize Important Stats On state enter
//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);
@ -19,12 +19,16 @@ public class MoveSlideState : MoveBaseState
}
public override void ExitState(MoveStateManager mSM, MoveBaseState 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;
}
@ -40,7 +44,11 @@ public class MoveSlideState : MoveBaseState
}
public override void FixedUpdateState(MoveStateManager 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
@ -82,6 +90,8 @@ public class MoveSlideState : MoveBaseState
}
}
*/
//actual slide movement
mSM.SlideMovement();
}
}

View File

@ -20,12 +20,14 @@ public class MoveIdleState : MoveBaseState
}
//If Q or joystick button1 crouch state
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)){
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(MoveStateManager mSM){
//actual directional movement
mSM.DirectionalMovement();
}
}

View File

@ -24,12 +24,14 @@ public class MoveJogState : MoveBaseState
}
//move to slide if Q or JoystickButton1
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)){
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(MoveStateManager mSM){
//actual directional movment
mSM.DirectionalMovement();
}
}

View File

@ -20,12 +20,13 @@ public class MoveRunState : MoveBaseState
}
//move to slide if Q or JoystickButton1
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)){
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(MoveStateManager mSM){
//actual direction movement
mSM.DirectionalMovement();
}
}

View File

@ -24,12 +24,13 @@ public class MoveWalkState : MoveBaseState
}
//move to slide if Q or JoystickButton1
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)){
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(MoveStateManager mSM){
//actual directional movemnt
mSM.DirectionalMovement();
}
}

View File

@ -4,10 +4,12 @@ using UnityEngine;
public class NitroCooldownState : NitroBaseState
{
bool cooldown = false;
bool cooldown = false; // whether or not cooldown has ended
public override void EnterState(NitroStateManager nSM, NitroBaseState previousState){
cooldown = false;
cooldown = false; // cooldown hasn't ended
//start cooldown
nSM.StartCoroutine(startCoolDown(nSM));
}
@ -16,9 +18,13 @@ public class NitroCooldownState : NitroBaseState
}
public override void UpdateState(NitroStateManager 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);
}
@ -28,6 +34,7 @@ public class NitroCooldownState : NitroBaseState
}
//cooldown timer
private IEnumerator startCoolDown(NitroStateManager nSM){
//nSM.driver.startUICooldown("Nitro");
yield return new WaitForSeconds(nSM.nitroItem.cooldownM);

View File

@ -13,6 +13,8 @@ public class NitroIncapacitatedState : NitroBaseState
}
public override void UpdateState(NitroStateManager nSM){
//if no longer incapacitated then None
if(nSM.mSM.currentState != nSM.mSM.RagdollState && nSM.mSM.currentState != nSM.mSM.RecoveringState){
nSM.SwitchState(nSM.NoneState);
}

View File

@ -5,32 +5,37 @@ using UnityEngine;
public class NitroNitroingState : NitroBaseState
{
private float tempTimer;
private float actualMaxVel;
private float actualAcc;
private float tempTimer; // temporary timer
private float actualMaxVel; // actual max velocity
private float actualAcc; // actual acceleration
public override void EnterState(NitroStateManager nSM, NitroBaseState previousState){
actualMaxVel = nSM.pStats.MaxVel;
actualAcc = nSM.pStats.Acc;
nSM.pStats.Acc += nSM.nitroAccBoost;
nSM.pStats.MaxVel += nSM.nitroVelBoost;
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;
tempTimer = 5; // how long we will be sped up
}
public override void ExitState(NitroStateManager nSM, NitroBaseState nextState){
nSM.pStats.Acc = actualAcc;
nSM.pStats.MaxVel = actualMaxVel;
nSM.pStats.Acc = actualAcc; // reset acceleration
nSM.pStats.MaxVel = actualMaxVel; // reset maximum velocity
}
public override void UpdateState(NitroStateManager 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);
}

View File

@ -13,16 +13,21 @@ public class NitroNoneState : NitroBaseState
}
public override void UpdateState(NitroStateManager 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 ((Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.JoystickButton8)))
//if pressing left shift then nitroing
else if ((Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.JoystickButton8)))
{
nSM.SwitchState(nSM.NitroingState);
}
if(nSM.mSM.currentState == nSM.mSM.RagdollState){
nSM.SwitchState(nSM.IncapacitatedState);
}
}
}

View File

@ -29,12 +29,12 @@ public class NitroStateManager : NetworkBehaviour
////Scripts Section
public PlayerStats pStats; // Player Stats
public MoveStateManager mSM;
public CoolDown driver;
public MoveStateManager mSM; // move state manager
public CoolDown driver; // cooldown driver
////
////Items Section
public SpecialItem nitroItem;
public SpecialItem nitroItem; // nitro item
////
////Variables Section

View File

@ -5,38 +5,46 @@ using UnityEngine;
public class OffenseAirKickState : OffenseBaseState
{
private float legRotation = 0;
bool kicked = false;
private float legRotation = 0; // angle for leg rotation
bool kicked = false; // whether they have kicked or not
public override void EnterState(OffenseStateManager oSM, OffenseBaseState previousState){
oSM.leg.SetActive(true);
legRotation = -90;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
kicked = false;
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(OffenseStateManager oSM, OffenseBaseState nextState){
legRotation = 0;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
oSM.leg.SetActive(false);
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(OffenseStateManager 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(OffenseStateManager 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;

View File

@ -5,38 +5,46 @@ using UnityEngine;
public class OffenseAirPunchState : OffenseBaseState
{
private float legRotation = 0;
bool kicked = false;
private float legRotation = 0; // angle for leg rotation
bool kicked = false; // whether they have kicked or not
public override void EnterState(OffenseStateManager oSM, OffenseBaseState previousState){
oSM.leg.SetActive(true);
legRotation = -90;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
kicked = false;
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(OffenseStateManager oSM, OffenseBaseState nextState){
legRotation = 0;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
oSM.leg.SetActive(false);
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(OffenseStateManager 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(OffenseStateManager 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;

View File

@ -5,35 +5,41 @@ using UnityEngine;
public class OffenseKickState : OffenseBaseState
{
float legRotation = 0;
bool kicked = false;
float legRotation = 0; // angle for leg rotation
bool kicked = false; // whether they have kicked or not
public override void EnterState(OffenseStateManager oSM, OffenseBaseState previousState){
oSM.leg.SetActive(true);
kicked = false;
oSM.leg.SetActive(true); // activate leg
kicked = false; // haven't kicked
//start kicking routine
oSM.StartCoroutine(kicking(1f));
}
public override void ExitState(OffenseStateManager oSM, OffenseBaseState nextState){
legRotation = 0;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
oSM.leg.SetActive(false);
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(OffenseStateManager 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(OffenseStateManager 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;
@ -41,9 +47,12 @@ public class OffenseKickState : OffenseBaseState
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;

View File

@ -5,35 +5,41 @@ using UnityEngine;
public class OffensePunchState : OffenseBaseState
{
float legRotation = 0;
bool kicked = false;
float legRotation = 0; // angle for leg rotation
bool kicked = false; // whether they have kicked or not
public override void EnterState(OffenseStateManager oSM, OffenseBaseState previousState){
oSM.leg.SetActive(true);
kicked = false;
oSM.leg.SetActive(true); // activate leg
kicked = false; // haven't kicked
//start kicking routine
oSM.StartCoroutine(kicking(1f));
}
public override void ExitState(OffenseStateManager oSM, OffenseBaseState nextState){
legRotation = 0;
oSM.leg.transform.eulerAngles = new Vector3(legRotation, oSM.leg.transform.eulerAngles.y, oSM.leg.transform.eulerAngles.z);
oSM.leg.SetActive(false);
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(OffenseStateManager 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(OffenseStateManager 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;
@ -41,9 +47,12 @@ public class OffensePunchState : OffenseBaseState
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;

View File

@ -4,11 +4,12 @@ using UnityEngine;
public class OffenseCooldownState : OffenseBaseState
{
bool cooldown = false;
bool cooldown = false; // whether or not cooldown is over
public override void EnterState(OffenseStateManager oSM, OffenseBaseState previousState){
cooldown = false;
cooldown = false; // cooldown isn't over
//start cooldown
oSM.StartCoroutine(kickCooldown());
}
@ -17,9 +18,13 @@ public class OffenseCooldownState : OffenseBaseState
}
public override void UpdateState(OffenseStateManager 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);
}
@ -29,6 +34,7 @@ public class OffenseCooldownState : OffenseBaseState
}
//kick cooldown
private IEnumerator kickCooldown(){
yield return new WaitForSeconds(.5f);
cooldown = true;

View File

@ -13,6 +13,8 @@ public class OffenseIncapacitatedState : OffenseBaseState
}
public override void UpdateState(OffenseStateManager 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);
}

View File

@ -13,22 +13,36 @@ public class OffenseNoneState : OffenseBaseState
}
public override void UpdateState(OffenseStateManager 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);
}

View File

@ -36,8 +36,8 @@ public class OffenseStateManager : NetworkBehaviour
////Scripts Section
public PlayerStats pStats; // Player Stats
public MoveStateManager mSM;
public AerialStateManager aSM;
public MoveStateManager mSM; // move state manager
public AerialStateManager aSM; // aerial state manager
////
void Awake(){
@ -60,7 +60,7 @@ public class OffenseStateManager : NetworkBehaviour
////Initialize Scripts
pStats = GetComponent<PlayerStats>(); // set PlayerStats
mSM = GetComponent<MoveStateManager>(); // set move state manager
aSM = GetComponent<AerialStateManager>();
aSM = GetComponent<AerialStateManager>(); // set aerial state manager
////
}
@ -99,9 +99,10 @@ public class OffenseStateManager : NetworkBehaviour
currentState.EnterState(this, previousState);
}
//Collision checker for the leg
private void OnCollisionEnter(Collision collision)
{
//if (!IsLocalPlayer) { return; }
if (!IsLocalPlayer) { return; }
Collider myCollider = collision.contacts[0].thisCollider;
if (collision.transform.CompareTag("kickable") && myCollider == legHitbox.GetComponent<Collider>()){
if(collision.gameObject.GetComponent<Rigidbody>().isKinematic == true){

View File

@ -17,7 +17,7 @@ public class PlayerCam : NetworkBehaviour
void Update ()
{
//if (!IsLocalPlayer) { return; }
if (!IsLocalPlayer) { return; }
offset = transform.parent.forward * rad.magnitude;
transform.position = new Vector3((player.transform.position.x - offset.x),((player.transform.position.y - offset.y)+3),(player.transform.position.z - offset.z));

View File

@ -24,17 +24,17 @@ EditorUserSettings:
value: 22424703114646703f313f3611314b0506241b2f222d69032e2c1336add32039f0f323f9d4393a323c34bf6d4a2b0f36e613
flags: 0
RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb
flags: 0
RecentlyUsedScenePath-8:
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c731f1415016439262f2434
flags: 0
RecentlyUsedScenePath-9:
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb
flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0