Removed Old Files

This commit is contained in:
Melby
2022-05-01 15:30:22 -05:00
parent b2841aa4b9
commit 010f58f21f
34 changed files with 0 additions and 15482 deletions

View File

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

View File

@@ -1,101 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
public class dBlink : NetworkBehaviour{
// Start is called before the first frame update
public Camera cam;
public CharacterController controller;
//Blink Variables
private LineRenderer beam;
private Vector3 origin;
private Vector3 endPoint;
private Vector3 mousePos;
private RaycastHit hit;
LayerMask ignoreP;
/////
private void Awake()
{
beam = gameObject.AddComponent<LineRenderer>();
beam.startWidth = 0.2f;
beam.endWidth = 0.2f;
beam.enabled = false;
ignoreP = LayerMask.GetMask("Player");
controller = GetComponent<CharacterController>();
}
void Start(){
// Grab the main camera.
//camera transform
}
//ADJUST SO DISTANCE IS DETERMINED BY SCROLL WHEEL
//blinks the player forwards
public void BlinkMove()
{
//if (!IsLocalPlayer) { return; }
if (Input.GetMouseButton(1))
{
// Finding the origin and end point of laser.
origin = transform.position + transform.forward * transform.lossyScale.z;
// Finding mouse pos in 3D space.
mousePos = Input.mousePosition;
mousePos.z = 20f;
endPoint = cam.ScreenToWorldPoint(mousePos);
// Find direction of beam.
Vector3 dir = endPoint - origin;
dir.Normalize();
// Are we hitting any colliders?
if (Physics.Raycast(origin, dir, out hit, 20f))
{
// If yes, then set endpoint to hit-point.
endPoint = hit.point;
}
// Set end point of laser.
beam.SetPosition(0, origin);
beam.SetPosition(1, endPoint);
// Draw the laser!
beam.enabled = true;
/*Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit raycastHit;
if (Physics.Raycast(ray, out raycastHit, 5.0f)){
LineRenderer.SetPosition(1, raycastHit.point);
}*/
}
else if (!Input.GetMouseButton(1) && beam.enabled == true)
{
beam.enabled = false;
//if teleporting due to hit to object, bump them a bit outside normal
if (hit.point != null)
{
transform.position = endPoint + hit.normal * 1.25f;
}
//if teleporting in the air or something, just spawn at endpoint
else
{
transform.position = endPoint;
}
//reenable character controller
}
}
}

View File

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

View File

@@ -1,63 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
public class dDash : NetworkBehaviour{
private CoolDown driver;
public Vector3 moveDirection;
public const float maxDashTime = 1.0f;
public float dashDistance = 10;
public float dashStoppingSpeed = 0.1f;
public SpecialItem dashItem;
private bool isOnCoolDown = false;
float currentDashTime = maxDashTime;
float dashSpeed = 12;
CharacterController characterController;
dPlayerMovement pMove;
void Start(){
//driver = GameObject.Find("Canvas").GetComponent<CoolDown>();
characterController = this.gameObject.GetComponent<CharacterController>();
pMove = GetComponent<dPlayerMovement>();
}
//UPDATE CHECK FOR MOVEMENT ONLY WHEN DASHING
void FixedUpdate(){
if(pMove.pStats.HasDash) DashPlayer();
}
void DashPlayer(){
//if (!IsLocalPlayer) { return; }
if(characterController.enabled == true){
if ((Input.GetKeyDown(KeyCode.R) || Input.GetAxis("Dash") != 0) && isOnCoolDown == false)
{
currentDashTime = 0;
StartCoroutine(startCoolDown());
}
if(currentDashTime < maxDashTime)
{
moveDirection = transform.forward * dashDistance;
currentDashTime += dashStoppingSpeed;
}
else
{
moveDirection = Vector3.zero;
}
characterController.Move(moveDirection * Time.deltaTime * dashSpeed);
}
}
private IEnumerator startCoolDown(){
Debug.Log("start corotine");
isOnCoolDown = true;
driver.startUICooldown(dashItem.name);
yield return new WaitForSeconds(dashItem.cooldownM);
isOnCoolDown = false;
Debug.Log("end corotine");
}
}

View File

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

View File

@@ -1,325 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
public class dGrapplingHook : NetworkBehaviour
{
public float maxGrappleDistance = 20;
public float maxGrabDistance = 30;
public bool isGrappled;
private int hookPointIndex;
private GameObject hookPoint;
private GameObject[] hookPoints;
private float distance;
private CharacterController movementController;
private dPlayerMovement playerMovement;
private PlayerStats pStats;
[SerializeField] private float ropeLength;
private float climbRate = 5;
private Vector3 swingDirection;
float inclinationAngle;
float theta = -1;
private float maxSwingSpeed = 50;
private float minSwingSpeed = 20;
private float swingAcc = 3f;
private float swingSpeed = 10;
private float swingMom;
private float maxSwingMom = 60;
private Vector3 tensionMomDirection;
private Vector3 hookPointRight;
private Vector3 momDirection;
private Vector3 curXZDir;
private Vector3 oldXZDir;
private bool swingback = false; //swing the player back
private float oldSwingMom;
Vector3 tensionDirection;
float tensionForce;
public Vector3 forceDirection;
private Vector3 tempRelease;
private Vector3 lerpRelease;
bool release = false;
// Start is called before the first frame update
void Start()
{
isGrappled = false;
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
movementController = gameObject.GetComponent<CharacterController>();
playerMovement = gameObject.GetComponent<dPlayerMovement>();
pStats = gameObject.GetComponent<PlayerStats>();
}
// Update is called once per frame
void Update()
{
//if (!IsLocalPlayer) { return; }
if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && pStats.HasGrapple) //If grapple button is hit
{
if (!isGrappled) //If we are not grappling
{
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
ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position);
if(ropeLength > maxGrappleDistance){
ropeLength = maxGrappleDistance;
}
oldXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized;
curXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized;
swingMom = CalculateSwingMom(playerMovement.driftVel.magnitude * 50f);
oldSwingMom = swingMom;
playerMovement.g = -1;
isGrappled = true; //toggle grappling state
release = false;
lerpRelease = Vector3.zero;
}
}
else //Else we are grappling
{
isGrappled = false; //toggle grappling state to release
release = true;
playerMovement.g = 0;
}
}
}
private void FixedUpdate()
{
//if (!IsLocalPlayer) { return; }
if (isGrappled)
{
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
//Extend Hook
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.JoystickButton4))
{
ropeLength += climbRate * Time.deltaTime;
if (ropeLength > maxGrappleDistance)
{
ropeLength = maxGrappleDistance;
}
//Debug.Log(ropeLength.ToString());
}
//Retract Hook
if (Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.JoystickButton5))
{
ropeLength -= climbRate * Time.deltaTime;
if (ropeLength < 8)
{
ropeLength = 8;
}
//Debug.Log(ropeLength.ToString());
}
//Debug.Log(Vector3.Distance(gameObject.transform.position, hookPoint.transform.position));
//Calculate tether force direction based on hookpoint
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) >= ropeLength )
{
Debug.Log(ropeLength);
forceDirection = CalculateForceDirection(1, playerMovement.g, hookPoint.transform.position) + RopeLengthOffset(hookPoint.transform.position, Vector3.Distance(gameObject.transform.position, hookPoint.transform.position));
}
else{
forceDirection = Vector3.zero;
}
//apply special swing movement when aerial
if(!playerMovement.isGrounded){
movementController.Move(SwingMoveController());
if(swingMom != 0){
movementController.Move(CalculateMomentumDirection(playerMovement.g, hookPoint.transform.position));
swingMom -= .5f;
}
}
else{
swingMom = CalculateSwingMom(playerMovement.driftVel.magnitude * 50f);
}
if(swingMom<0) swingMom = 0;
tempRelease = CalculateSwingReleaseForce();
}
else if(!isGrappled){
//Reset force direction after unhook
forceDirection = Vector3.zero;
swingback = true;
if(release){
lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 10f * Time.deltaTime);
tempRelease *= .99f;
Debug.Log(lerpRelease);
movementController.Move(lerpRelease);
}
}
//WILL NEED ADJUSTMENT OR REMOVAL IN THE FUTURE
//ungrapple on jump
if(playerMovement.jumpHeld && !playerMovement.isGrounded && isGrappled){
release = true;
isGrappled = false;
}
if(playerMovement.isGrounded){
swingback = true;
release = 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;
}
//Needs to be Overhauled to properly implement energy loss taking into account players current Velocity, height and input
//------Important Equations--------
// TensionForce = Cos(theta) * g * m * Vector3(tensionDirection)
// Potential Energy = m * g * h -- Will need to modify adding current speed
// Kinetic Energy = 1/2 * m * V^2 -- assuming no energy loss at the bottom KE = PE at peak we will add energy loss ourselves
// Total Energy = m * ((g*h) + (1/2 * V^2))
// Velocity = (2 * ((TotalEnergy/m) - (g*h)))^(1/2) -- This hypothetically could be used for our swing momentum calculation
// Movement Direction right angle of tension force = Sin(theta) * g * m * Vector3(Right angle to tensionDirection)
//Calculate the tether direction vector and how much force that vector needs
Vector3 CalculateForceDirection(float mass, float g, Vector3 hPoint){
//tension direction and angle calculation
tensionDirection = (hPoint - transform.position).normalized;
inclinationAngle = Vector3.Angle((transform.position - hPoint).normalized, -transform.up);
theta = Mathf.Deg2Rad * inclinationAngle;
if(theta<=.1) theta = 0;
//How much force the tension needs
tensionForce = mass * -g * Mathf.Cos(theta);
//force direction calculation based on tension direction and force
Vector3 fDirection = tensionDirection * tensionForce;
return fDirection;
}
Vector3 CalculateMomentumDirection(float g, Vector3 hPoint){
tensionMomDirection = (hPoint - transform.position).normalized;
hookPointRight = Vector3.Cross(oldXZDir, transform.up).normalized;
momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized;
if(oldXZDir != curXZDir){
//midpointMom = swingMom;
swingback = false;
//Debug.Log("flip");
}
if(swingback == false && swingMom <= (oldSwingMom*(.75f))){
swingback = true;
oldSwingMom = swingMom;
oldXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized;
//Debug.Log("swingback");
}
curXZDir = (new Vector3(hPoint.x,0,hPoint.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized;
Debug.DrawRay(transform.position, momDirection * Time.deltaTime* 100, Color.green);
return (momDirection * Time.deltaTime * swingMom);
}
//Calculates the players initial swing momentum using their height and their current velocity
float CalculateSwingMom(float playerSpeed){
//Calculate the players height compared to the lowest point in the swing
float swingHeight = transform.position.y - (hookPoint.transform.position.y - ropeLength);
if(swingHeight <= 1){
swingHeight = 1;
}
float sMom = playerSpeed + (swingHeight*2);
if(sMom > maxSwingMom){
sMom = maxSwingMom;
}
return sMom;
}
//Special movement for the player while they swing
Vector3 SwingMoveController(){
//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 < maxSwingSpeed){
swingSpeed += swingAcc;
}
else if((inputVert != 0 || inputHor != 0) && swingSpeed >= maxSwingSpeed){
swingSpeed = maxSwingSpeed;
}
else if((inputVert == 0 && inputHor == 0)){
swingSpeed = minSwingSpeed;
}
//Swing direction based on player input
swingDirection = Vector3.Cross(tensionDirection, ((transform.right * -inputVert) + (transform.forward * inputHor))).normalized;
//NEED TO ADD SWINGSPEED EASING
//this could be just adding a gradual increase in the swing speed instead of using a flat rate
//Swing movement with swing speed added
Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed);
return (swingMovement);
}
Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance){
//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 - transform.position).normalized;
return tenDirOffset * offsetPower * Time.deltaTime;
}
Vector3 CalculateSwingReleaseForce(){
Vector3 releaseSwingForceDirection = momDirection * ((swingMom) + 10);
releaseSwingForceDirection = new Vector3(releaseSwingForceDirection.x,0,releaseSwingForceDirection.z);
if(swingMom < 5){
return Vector3.zero;
}
return releaseSwingForceDirection * Time.deltaTime;
}
}

View File

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

View File

@@ -1,107 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
public class dKickController : NetworkBehaviour
{
private GameObject leg;
private GameObject legHitbox;
private bool isKicking = false;
//slightly bad practice, when merging find a better work around
private bool isDiveKicking = false;
private CharacterController characterController;
public dPlayerMovement pMove;
public PlayerStats pStats;
private float legRotation = 0;
void Start(){
pStats = GetComponent<PlayerStats>();
pMove = GetComponent<dPlayerMovement>();
characterController = this.gameObject.GetComponent<CharacterController>();
leg = transform.Find("Leg").gameObject;
legHitbox = leg.transform.Find("LegHitbox").gameObject;
leg.SetActive(false);
}
void Update(){
Kick();
}
void Kick(){
//if (!IsLocalPlayer) { return; }
//Note: when we merge this into PlayerMovement, we may want to change isgrounded to our
//custom is grounded
//If F is pressed or gamepad right trigger is pulled
if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isGrounded == false && pMove.isSliding==false)
{
Debug.Log("dive");
// if kicking in air, kick until grounded (maybe add some foward momentum if needeD)
isKicking = true;
isDiveKicking = true;
leg.SetActive(true);
legRotation = -90;
}
//otherwise do ground kick for .3 seconds
else if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isSliding==false){
StartCoroutine(Kicking(1f));
}
//once dive kick touches ground, set back to normal state
if (pMove.isGrounded == true && isDiveKicking == true)
{
isDiveKicking = false;
isKicking = false;
legRotation = 0;
leg.transform.eulerAngles = new Vector3(legRotation, leg.transform.eulerAngles.y, leg.transform.eulerAngles.z);
leg.SetActive(false);
}
if(isKicking){
RotateLeg();
characterController.Move(new Vector3(.0015f,0,0));
}
}
private IEnumerator Kicking(float waitTime){
isKicking = true;
leg.SetActive(true);
yield return new WaitForSeconds(waitTime);
isKicking = false;
legRotation = 0;
leg.transform.eulerAngles = new Vector3(legRotation, leg.transform.eulerAngles.y, leg.transform.eulerAngles.z);
leg.SetActive(false);
}
private void OnCollisionEnter(Collision collision)
{
//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){
collision.gameObject.GetComponent<Rigidbody>().isKinematic = false;
}
Vector3 direction = this.transform.forward;
Debug.Log(direction);
collision.rigidbody.AddForce(direction * pStats.KickPow, ForceMode.Impulse);
}
if (collision.transform.CompareTag("destroyable") && myCollider == legHitbox.GetComponent<Collider>()){
collision.transform.gameObject.GetComponent<BreakableBlock>().damage(pStats.KickPow);
}
}
private void RotateLeg(){
if(legRotation > -90){
leg.transform.eulerAngles = new Vector3(legRotation, leg.transform.eulerAngles.y, leg.transform.eulerAngles.z);
legRotation -= 20;
}
else{
legRotation = -90;
Debug.Log("Kick Full Extension");
}
}
}

View File

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

View File

@@ -1,65 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class dNitro : MonoBehaviour
{
private CoolDown driver;
private PlayerStats playerStats;
public SpecialItem nitroItem;
private bool isOnCoolDown = false;
public bool isNitroing = false;
private float tempTimer = 5;
//this will need to be set from scritable object or something;
// Start is called before the first frame update
void Start()
{
//driver = GameObject.Find("Canvas").GetComponent<CoolDown>();
playerStats = GetComponent<PlayerStats>();
}
// Update is called once per frame
void Update()
{
//once cooldowns are implemented, put this on one (a long one)
if ((Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.JoystickButton8)) && isOnCoolDown == false && playerStats.HasNitro)
{
isNitroing = true;
}
}
void FixedUpdate(){
if(isNitroing){
if(tempTimer > 0){
tempTimer -= .02f;
Debug.Log("nitro is on");
if(playerStats.CurVel < playerStats.HardCapMaxVel){
playerStats.CurVel += playerStats.Acc * 50;
}
else if(playerStats.CurVel > playerStats.HardCapMaxVel){
playerStats.CurVel = playerStats.HardCapMaxVel;
}
}
else{
StartCoroutine(startCoolDown());
isNitroing = false;
}
}
}
private IEnumerator startCoolDown(){
Debug.Log("start corotine");
isOnCoolDown = true;
driver.startUICooldown("Nitro");
yield return new WaitForSeconds(nitroItem.cooldownM);
isOnCoolDown = false;
tempTimer = 5;
Debug.Log("end corotine");
}
}

View File

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

View File

@@ -1,202 +0,0 @@
using UnityEngine;
using System.Linq;
using MLAPI;
using UnityEngine.Rendering;
[RequireComponent (typeof(dPlayerMovement))]
public class dWallRun : NetworkBehaviour
{
public float wallMaxDistance = 3f;
public float wallSpeedMultiplier = 1.2f;
public float minimumHeight = .1f;
public float maxAngleRoll = 20;
[Range(0.0f, 1.0f)]
public float normalizedAngleThreshold = 0.1f;
public float jumpDuration = .02f;
public float wallBouncing = 3;
public float cameraTransitionDuration = 1;
public float wallGravityDownForce = 2.8f;
[Space]
dPlayerMovement playerMovementController;
Vector3[] directions;
RaycastHit[] hits;
bool isWallRunning = false;
public bool firstAttach = false;
Vector3 lastWallPosition;
Vector3 lastWallNormal;
float elapsedTimeSinceJump = 0;
float elapsedTimeSinceWallAttach = 0;
float elapsedTimeSinceWallDetatch = 0;
bool jumping;
bool isPlayergrounded() => playerMovementController.isGrounded;
public bool IsWallRunning() => isWallRunning;
bool CanWallRun()
{
float verticalAxis = Input.GetAxisRaw("Vertical");
return !isPlayergrounded() && verticalAxis > 0 && VerticalCheck();
}
bool VerticalCheck(){
return !Physics.Raycast(transform.position, Vector3.down, minimumHeight);
}
void Start(){
playerMovementController = GetComponent<dPlayerMovement>();
directions = new Vector3[]{
Vector3.right,
Vector3.right + Vector3.forward,
Vector3.forward,
Vector3.left + Vector3.forward,
Vector3.left
};
}
public void WallRunRoutine(){
//if (!IsLocalPlayer) { return; }
isWallRunning = false;
hits = new RaycastHit[directions.Length];
if(playerMovementController.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;
}
}
bool CanAttach()
{
if(jumping)
{
elapsedTimeSinceJump += Time.deltaTime;
if(elapsedTimeSinceJump > jumpDuration)
{
elapsedTimeSinceJump = 0;
jumping = false;
}
return false;
}
return true;
}
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 * playerMovementController.PlayerSpeed() * Time.deltaTime;// * wallSpeedMultiplier;
Vector3 velNorm = playerMovementController.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;
//
playerMovementController.vel = moveToSet;
if(!isWallRunning){
firstAttach = true;
isWallRunning = true;
}
if(playerMovementController.curJumpNum == playerMovementController.pStats.JumpNum){
playerMovementController.curJumpNum = 0;
}
}
}
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;
}
public Vector3 GetWallJumpDirection() //Add call in jump where if we are wallrunning and jump, the jump vector is multiplied by this
{
return lastWallNormal * wallBouncing + (transform.up);
}
}

View File

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

View File

@@ -1,596 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
using UnityEngine.UI;
public class dPlayerMovement : NetworkBehaviour
{
////Objects Sections
private GameObject parentObj; // Parent object
public Camera cam; // Camera object
////
////Components Section
private CharacterController moveController; // Character Controller
private Rigidbody rB; // Players Rigidbody
private CapsuleCollider capCol; // Players Capsule Collider
private Animator animator; // Animation Controller
////
////Scripts Section
public PlayerStats pStats; // Player Stats
private dGrapplingHook grapple; // Grappling Hook
private dNitro nitro; // Nitro
private dWallRun wallRun; // Wallrun
////
////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 Vel based on curVel
//Jump Variables
public int curJumpNum; // current Jumps Used
public bool jumpHeld; // Jump is Held
private bool jumpPressed; // Jamp was pressed
float coyJumpTimer = 0.1f; // Default Coyote Jump time
float curCoyJumpTimer = 0.1f; // current Coyote Jump time
public float lowJumpMultiplier; // Short jump multiplier
public float fallMultiplier; // High Jump Multiplier
//Gravity Variables
public float g = 0; // player downwards velocity
private float maxG = -100; // max downwards velocity
//Glide Variables
private bool tempSetTraction = false; // has the Traction been temporarily set
private float tempTraction = 0.0f; // temporary traction
//Impact Variables
private float mass = 5.0F; // mass variable for Impact
private Vector3 impact = Vector3.zero; // Impact Vector
private float distToGround; // distance to ground
//Ground Check
public bool isGrounded; // is player grounded
public float groundCheckDistance = 0.05f; // offset distance to check ground
private float lastTimeJumped = 0f; // Last time the player jumped
private const float jumpGroundingPreventionTime = 0.2f; // delay so player doesn't get snapped to ground while jumping
private const float groundCheckDistanceInAir = 0.07f; // How close we have to get to ground to start checking for grounded again
private Ray groundRay; // ground ray
private RaycastHit groundHit; // ground raycast
//Camera Variables
private Vector3 camRotation; // cameras camera rotation vector
[Range(-45, -15)]
public int minAngle = -30; // minimum downwards cam angle
[Range(30, 80)]
public int maxAngle = 45; // Max upwards cam angle
[Range(50, 500)]
public int sensitivity = 200; // Camera sensitivity
//Ragdoll variables
private bool firstHit = false; // has first contact happened
private bool beginRagTimer = false; // beging ragdoll timer bool
private float ragTime; // ragdoll timer
private Vector3 prevRot; // Save last rotation before hit
//Slide Variables
public bool isSliding = false; // If player is sliding /////////// Maybe unnecessary once state machine is implemented
private float originalTraction; // Original Traction
private RaycastHit slideRay; // slide raycast
private Vector3 slideUp; // Slide upwards direction
private bool qDown; // is q being pressed
private float tempSlideCurVel; // temp vel while sliding so they don't lose speed
////
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
wallRun = GetComponent<dWallRun>(); // set Wallrun
grapple = GetComponent<dGrapplingHook>(); // set grapplingHook
nitro = GetComponent<dNitro>(); // set Nitro
////
}
void Start(){
////Initialize important starting variables
distToGround = GetComponent<Collider>().bounds.extents.y; // set players distance to ground
slideUp = GetComponentInParent<Transform>().up; // get parents up direction
////
// Don't do movement unless this is the local player controlling it
// Otherwise we let the server handle moving us
//if (!IsLocalPlayer) { return; }
// Don't lock the cursor multiple times if this isn't the local player
// Also don't want to lock the cursor for the king
// That is why this is after the LocalPlayer check
Cursor.lockState = CursorLockMode.Locked; // Lock cursor on start if you are the local player
}
// Update is called once per frame
void FixedUpdate(){
// Don't do movement unless this is the local player controlling it
// Otherwise we let the server handle moving us
//if (!IsLocalPlayer) { return; }
//Controls for camera
if(cam.enabled) Rotation();
else Debug.Log("Cam Disabled");
//Allow Movement when moveController is enabled
if(moveController.enabled == true){
//input controls for movement
InputController();
//Dissipates Impact
DissipateImpact();
}
//If Character controller is disabled use rigidbody calculations
else{
//if ragdoll timer is over disable ragdolling
if (RagdollTimer() == 0){
firstHit = false;
DisableRagdoll();
}
//Gravity without moveController
g -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,g,0));
}
/////ONLY FOR DEBUG PURPOSES REMOVE WHEN UNNECESSARY
if (transform.position.y < -5)
{
TeleportPlayer(new Vector3(0,100,0));
}
}
////Input Related Functions
//Reads inputs and moves player
private void InputController(){
//Check if player is grounded before each frame
GroundCheck();
//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();
//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);
//Gravity and Jump calculations
UpdateGravity();
Jump();
Vector3 moveY = new Vector3(0,g,0);
//Slide Function
Slide();
//move animation
//if vel from input is greater than 0, start sprinting animation
if (PlayerSpeed() > 0.1)
{
//Debug.Log(driftVel.magnitude);
if(animator != null) animator.SetBool("isRunning", true);
}
//if low enough movement from player (this will be still at this value) stop animation
else if (driftVel.magnitude < .05f)
{
driftVel = Vector3.zero;
if(animator != null) animator.SetBool("isRunning", false);
}
//Move Player
if(grapple.isGrappled && !isGrounded){
driftVel = Vector3.zero;
moveController.Move(((moveY + grapple.forceDirection) * Time.deltaTime));
}
else{
moveController.Move(driftVel + (moveY * Time.deltaTime));
}
}
//Calculates speed current player needs to be going
public float PlayerSpeed(){
WallCheck();
//If nothing is pressed speed is 0
if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f) || isSliding || (grapple.isGrappled && !isGrounded))
{
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 && nitro.isNitroing == false)
{
pStats.CurVel = pStats.MaxVel;
return pStats.CurVel;
}
else if(nitro.isNitroing){
return pStats.CurVel;
}
else{
Debug.Log("Something has gone wrong with the PlayerSpeed()");
return -1;
}
}
//Need to implement to check if player has hit a wall in the direction they are moving and they should lose speed
private void WallCheck(){
//IMPLEMENT A RAYCAST CHECK
}
//Jump Function
private 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 && !isSliding)
{
if(wallRun.IsWallRunning()){
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 8.5f);
g = pStats.JumpPow;
curJumpNum = 0;
}
else{
g = pStats.JumpPow;
}
curJumpNum++;
jumpHeld = true;
jumpPressed = true;
}
//Last time Jumped
lastTimeJumped = Time.time;
//If grounded no jumps have been used and coyote Timer is refreshed
if(isGrounded && g == 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(grapple.isGrappled && curJumpNum == pStats.JumpNum) curJumpNum = 0;
//If space/south face gamepad button isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0){
jumpHeld = false;
}
if(g < 0){
jumpPressed = false;
}
}
//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;
}
}
}
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void UpdateGravity(){
//Gliding
if(pStats.HasGlider && g < 0 && Input.GetButton("Jump") && !isSliding){
//Gravity with glider
GravityCalculation(8);
//Set temp values to put traction back to normal
if(tempSetTraction == false){
tempTraction = pStats.Traction;
pStats.Traction = 1.0f;
tempSetTraction = true;
}
}
//if temporary values have been set restore them back to the normal values
else if(pStats.HasGlider && g==0 && tempSetTraction == true){
pStats.Traction = tempTraction;
tempSetTraction = false;
}
//Wallrunning
else if (pStats.HasWallrun) {
//Run wall run script
wallRun.WallRunRoutine();
//if wallrunning apply different gravity
if(wallRun.IsWallRunning()){
if(wallRun.firstAttach){
g = 0;
wallRun.firstAttach = false;
}
GravityCalculation(2);
}
//Normal gravity if not wallrunning
else{
GravityCalculation(pStats.PlayerGrav);
}
}
//Default Gravity
else{
//Normal gravity
GravityCalculation(pStats.PlayerGrav);
}
}
//Uses Given gravity to apply a downwards force while allowing coyote Jump and short hops
private void GravityCalculation(float grav){
//apply slight upwards force for jump smoothing when g < 0
if(g < 0){
g += grav * (fallMultiplier - 1) * Time.deltaTime;
}
//apply smaller upwards force if jump is released early when jumping creating a short jump
else if (g > 0 && !Input.GetButton("Jump")){
g += grav * (lowJumpMultiplier - 1) * Time.deltaTime;
}
//apply gravity if not grounded and coyote timer is less than 0
if((isGrounded == false && curCoyJumpTimer <= 0) || grapple.isGrappled){
g -= grav * Time.deltaTime;
}
//else don't apply gravity
else{
g = 0;
}
//Caps out the players downwards speed
if(g < maxG){
g = maxG;
}
}
//Slide Function
private void Slide(){
//if the q button or the east face button on gamepad is held down
if ((Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q))) {
qDown = true;
if (isSliding == false){
originalTraction = pStats.Traction;
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x - 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = true;
//if it can't find the animator (capsul prefab)
if (GetComponent<Animator>() == null){
moveController.height = 1.0f;
}
//if the regular model
else {
moveController.height *= .5f;
}
pStats.Traction = 0.01f;
}
tempSlideCurVel = driftVel.magnitude * 50f;
transform.Rotate(Vector3.forward * -sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
pStats.Traction += .004f;
}
else{
qDown = false;
}
//NOTE: potentialy change this to only allow player back up if there is nothing above them
if (qDown == false && isSliding == true) {
//if nothing is above the object, stop sliding
if (Physics.Raycast(this.gameObject.transform.position, slideUp, out slideRay, 5f) == false)
{
this.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
isSliding = false;
pStats.CurVel = tempSlideCurVel;
//if it can't find the animator (capsul prefab)
if (GetComponent<Animator>() == null)
{
moveController.height = 2.0f;
}
//if the regular model
else
{
moveController.height *= 2.0f;
}
pStats.Traction = originalTraction;
}
else{
Debug.Log("Object above you");
}
}
}
////
////Physics Calculation Unrelated to inputs
//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
private 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);
}
//Clear all stored movement
public void CancelMomentum(){
pStats.CurVel = 0;
vel = Vector3.zero;
moveX = Vector3.zero;
moveZ = Vector3.zero;
driftVel = Vector3.zero;
}
//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 ) //&& Time.time >= lastTimeJumped + jumpGroundingPreventionTime) // only try to detect ground if it's been a short amount of time since last jump; otherwise we may snap to the ground instantly after we try jumping
{
// 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 && !grapple.isGrappled)
{
moveController.Move(Vector3.down * groundHit.distance);
}
}
}
}
////
////Ragdoll Functions
//Player Gets Hit
public void GetHit(Vector3 dir, float force){
//if (!IsLocalPlayer) { return; }
if(firstHit == false){
EnableRagdoll();
dir.Normalize();
rB.AddForce(dir * force, ForceMode.Impulse);
firstHit = true;
}
}
//Enable Ragdoll and update all related variables
private void EnableRagdoll(){
ragTime = pStats.RecovTime;
prevRot = transform.localEulerAngles;
capCol.enabled = true;
moveController.enabled = false;
rB.isKinematic = false;
rB.detectCollisions = true;
}
//Disable Ragdoll and revert all ragdoll variables
private void DisableRagdoll(){
capCol.enabled = false;
moveController.enabled = true;
rB.isKinematic = true;
rB.detectCollisions = false;
transform.localEulerAngles = prevRot;
CancelMomentum();
}
//When to begin the ragdoll timer
private float RagdollTimer(){
if(beginRagTimer == false){
beginRagTimer = Physics.Raycast(transform.position, -Vector3.up, distToGround + 1f);
}
else if(ragTime <= 0){
ragTime = 0;
beginRagTimer = false;
}
if(beginRagTimer == true){
ragTime -= Time.deltaTime;
}
return ragTime;
}
////
//// Respawn and Relocation Functions
//Respawn timer
private IEnumerator RespawnTimer(){
float duration = 2f;
float normalizedTime = 0;
while (normalizedTime <= 1f)
{
normalizedTime += Time.deltaTime / duration;
yield return null;
}
moveController.enabled = true;
}
//Teleports player to new location
public void TeleportPlayer(Vector3 position, Quaternion rotation = new Quaternion()){
transform.position = position;
transform.rotation = rotation;
}
////
}

View File

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