This commit is contained in:
Evan Nydahl
2021-11-01 13:32:41 -05:00
109 changed files with 39207 additions and 584 deletions

View File

@@ -1,67 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrapplingHook : MonoBehaviour
{
public float maxGrappleDistance = 25;
private bool isGrappled;
private int hookPointIndex;
private GameObject hookPoint;
private GameObject[] hookPoints;
private float distance;
// Start is called before the first frame update
void Start()
{
isGrappled = false;
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E)) //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
//physics set up?
isGrappled = true; //toggle grappling state
}
}
else //Else we are grappling
{
//physics tear down?
isGrappled = false; //toggle grappling state to release
}
}
}
private void FixedUpdate()
{
if (isGrappled)
{
//Do grappling physics based on hookPoint
}
}
int FindHookPoint()
{
float least = maxGrappleDistance;
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;
}
}

View File

@@ -4,15 +4,17 @@ using UnityEngine;
public class InventoryManager : MonoBehaviour
{
public Item[] allItems;
private List<Item> itemList;
public List<Item> ItemList{
public Item[] allItems;
private List<Item> itemList;
public List<Item> ItemList{
get{ return itemList; }
set{ itemList = value; }
}
void Awake(){
allItems = Resources.LoadAll<Item>("ItemObjects");
}
void Awake(){
allItems = Resources.LoadAll<Item>("ItemObjects");
itemList = new List<Item>(allItems);
}
itemList = new List<Item>(allItems);
}
}

View File

@@ -20,7 +20,7 @@ public class Item: ScriptableObject {
public float playerGravM;
public int costM;
public virtual void Equip(PlayerStats p){
public virtual void Equip(PlayerStats p, GameObject player){
if(maxVelM != 0){
p.MaxVel += maxVelM;
}
@@ -50,7 +50,7 @@ public class Item: ScriptableObject {
}
}
public virtual void Unequip(PlayerStats p){
public virtual void Unequip(PlayerStats p, GameObject player){
if(maxVelM != 0){
p.MaxVel -= maxVelM;
}

View File

@@ -33,3 +33,4 @@ MonoBehaviour:
hasNitroM: 0
hasDashM: 0
cooldownM: 5
scriptM: {fileID: 11500000, guid: 5162a84172831f4449df60b9ad0ce22f, type: 3}

View File

@@ -33,3 +33,4 @@ MonoBehaviour:
hasNitroM: 0
hasDashM: 0
cooldownM: 0
scriptM: {fileID: 11500000, guid: 535009eaa735a4c4e95c6fc270e32741, type: 3}

View File

@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CreateAssetMenu]
public class SpecialItem : Item
@@ -12,8 +13,8 @@ public class SpecialItem : Item
public bool hasNitroM;
public bool hasDashM;
public float cooldownM;
public override void Equip(PlayerStats p){
public override void Equip(PlayerStats p, GameObject player){
if(maxVelM != 0){
p.MaxVel += maxVelM;
}
@@ -61,7 +62,7 @@ public class SpecialItem : Item
}
}
public override void Unequip(PlayerStats p){
public override void Unequip(PlayerStats p, GameObject player){
if(maxVelM != 0){
p.MaxVel -= maxVelM;
}
@@ -89,24 +90,25 @@ public class SpecialItem : Item
if(playerGravM != 0){
p.PlayerGrav -= playerGravM;
}
if(hasWallrunM != true){
p.HasWallrun = hasWallrunM;
if(hasWallrunM != false){
p.HasWallrun = false;
}
if(hasBlinkM != true){
p.HasBlink = hasBlinkM;
if(hasBlinkM != false){
p.HasBlink = false;
}
if(hasGrappleM != true){
p.HasGrapple = hasGrappleM;
if(hasGrappleM != false){
p.HasGrapple = false;
}
if(hasGliderM != true){
p.HasGlider = hasGliderM;
if(hasGliderM != false){
p.HasGlider = false;
}
if(hasNitroM != true){
p.HasNitro = hasNitroM;
if(hasNitroM != false){
p.HasNitro = false;
}
if(hasDashM != true){
p.HasDash = hasDashM;
if(hasDashM != false){
p.HasDash = false;
}
}
}

View File

@@ -1,15 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallRunItem : Item
{
public void Equip(PlayerStats p){
p.HasWallrun = true;
}
public void Unequip(PlayerStats p)
{
p.HasWallrun = false;
}
}

View File

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

View File

@@ -0,0 +1,99 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Blink : MonoBehaviour{
// Start is called before the first frame update
private 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
cam = GetComponentInChildren<Camera>();
}
//ADJUST SO DISTANCE IS DETERMINED BY SCROLL WHEEL
//blinks the player forwards
private void BlinkMove()
{
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,5 +1,5 @@
fileFormatVersion: 2
guid: c2c2e0314365de34c923bb88c9b334ca
guid: 5162a84172831f4449df60b9ad0ce22f
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dash : MonoBehaviour{
public Vector3 moveDirection;
public const float maxDashTime = 1.0f;
public float dashDistance = 10;
public float dashStoppingSpeed = 0.1f;
float currentDashTime = maxDashTime;
float dashSpeed = 12;
CharacterController characterController;
void Start(){
characterController = this.gameObject.GetComponent<CharacterController>();
}
//UPDATE CHECK FOR MOVEMENT ONLY WHEN DASHING
void FixedUpdate(){
if (Input.GetKeyDown(KeyCode.E))
{
currentDashTime = 0;
}
if(currentDashTime < maxDashTime)
{
moveDirection = transform.forward * dashDistance;
currentDashTime += dashStoppingSpeed;
}
else
{
moveDirection = Vector3.zero;
}
characterController.Move(moveDirection * Time.deltaTime * dashSpeed);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ed382e04d00059e40a6803fa4ad43469
guid: 980b3f40ede2d8a4c96587100cf71d02
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,104 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrapplingHook : MonoBehaviour
{
public float maxGrappleDistance = 25;
private bool isGrappled;
private int hookPointIndex;
private GameObject hookPoint;
private GameObject[] hookPoints;
private float distance;
private CharacterController movementController;
private PlayerMovement playerMovement;
private PlayerStats pStats;
private float ropeLength;
private float climbRate = 5;
// Start is called before the first frame update
void Start()
{
isGrappled = false;
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
movementController = gameObject.GetComponent<CharacterController>();
playerMovement = gameObject.GetComponent<PlayerMovement>();
pStats = gameObject.GetComponent<PlayerStats>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E)) //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) + 0.5f;
isGrappled = true; //toggle grappling state
}
}
else //Else we are grappling
{
//physics tear down?
isGrappled = false; //toggle grappling state to release
}
}
}
private void FixedUpdate()
{
if (isGrappled)
{
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
if (Input.GetKey(KeyCode.LeftShift)) //Extend hook
{
ropeLength += climbRate * Time.deltaTime;
if (ropeLength > maxGrappleDistance)
{
ropeLength = maxGrappleDistance;
}
//Debug.Log(ropeLength.ToString());
}
if (Input.GetKey(KeyCode.RightShift)) // Retract Hook
{
ropeLength -= climbRate * Time.deltaTime;
if (ropeLength < 5)
{
ropeLength = 5;
}
//Debug.Log(ropeLength.ToString());
}
//Do grappling physics based on hookPoint
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength)
{
//Impact Based
playerMovement.AddImpact((hookPoint.transform.position - gameObject.transform.position), pStats.PlayerGrav);
//Character controller move?
//movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength*Time.deltaTime);
//Lerp? or another smoother way? Better physics? Wait until refinement to deal with
}
}
}
int FindHookPoint()
{
float least = maxGrappleDistance;
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;
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Kick : MonoBehaviour
{
private float kickForce = 100f;
// Start is called before the first frame update
void Start(){
}
// Update is called once per frame
void Update(){
}
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.CompareTag("kickable")){
Vector3 direction = this.transform.forward;
Debug.Log(direction);
collision.rigidbody.AddForce(direction * kickForce, ForceMode.Impulse);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 80dbcf4212f11a74ebd5289c2b5eb309
guid: f9b52b0ade3c44e47a3a4dc48c47ec1c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KickController : MonoBehaviour
{
//Important, may want to change blink code to only work for trigger collider
// so that the player doesn't teleport to their leg
public GameObject leg;
private bool isKicking = false;
//slightly bad practice, when merging find a better work around
private bool isDiveKicking = false;
private CharacterController characterController;
void Start(){
characterController = this.gameObject.GetComponent<CharacterController>();
}
void Update(){
//Note: when we merge this into PlayerMovement, we may want to change isgrounded to our
//custom is grounded
if (Input.GetKeyDown(KeyCode.F) && isKicking == false && characterController.isGrounded == 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);
}
//otherwise do ground kick for .3 seconds
else if (Input.GetKeyDown(KeyCode.F) && isKicking == false){
Debug.Log("kick");
StartCoroutine(Kicking(.3f));
}
//once dive kick touches ground, set back to normal state
if(characterController.isGrounded == true && isDiveKicking == true){
isDiveKicking = false;
isKicking = false;
leg.SetActive(false);
}
}
private IEnumerator Kicking(float waitTime){
isKicking = true;
leg.SetActive(true);
yield return new WaitForSeconds(waitTime);
isKicking = false;
leg.SetActive(false);
}
}

View File

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

View File

@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Nitro : MonoBehaviour
{
private PlayerStats playerStats;
private CoolDown driver;
private bool isOnCoolDown = false;
//this will need to be set from scritable object or something;
private float coolDown;
// Start is called before the first frame update
void Start(){
playerStats = GetComponent<PlayerStats>();
coolDown = 5.0f;
//retrieves
driver = FindObjectOfType<CoolDown>();
}
// Update is called once per frame
void Update(){
//once cooldowns are implemented, put this on one (a long one)
if (Input.GetKeyDown(KeyCode.LeftShift) && isOnCoolDown == false){
playerStats.CurVel = playerStats.MaxVel;
StartCoroutine(startCoolDown());
}
}
private IEnumerator startCoolDown(){
Debug.Log("start corotine");
isOnCoolDown = true;
driver.startUICooldown("Nitro");
yield return new WaitForSeconds(coolDown);
isOnCoolDown = false;
}
}

View File

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

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Mote: This should be refactored at some point
public class Slide : MonoBehaviour{
public Camera playerCam;
private bool isSliding = false;
private CharacterController charController;
private PlayerStats playerStats;
private float orignalTraction;
private RaycastHit ray;
private Vector3 up;
private void Awake(){
charController = this.gameObject.GetComponentInParent<CharacterController>();
playerStats = this.gameObject.GetComponentInParent<PlayerStats>();
up = this.gameObject.GetComponentInParent<Transform>().up;
}
// Update is called once per frame
void Update(){
//Debug.DrawRay(this.gameObject.transform.position, up, Color.red, 5.0f);
//NOTE::
//if button is held down, start sliding
if (Input.GetKey(KeyCode.Q)){
if (isSliding == false){
orignalTraction = playerStats.Traction;
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x - 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = true;
charController.height = 1.0f;
playerStats.Traction = 0.01f;
}
}
//NOTE: potentialy change this to only allow player back up if there is nothing above them
if (Input.GetKeyUp(KeyCode.Q)) {
//if nothing is above the object, stop slidding
if (Physics.Raycast(this.gameObject.transform.position, up, out ray, 5f) == false)
{
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x - 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = false;
charController.height = 2.0f;
playerStats.Traction = orignalTraction;
}
else{
Debug.Log("Object above you");
}
}
//if button is not held down, and still slidding (if they let go but something was above them) check to see if something is still above them, if not
else if (Input.GetKey(KeyCode.Q) == false && isSliding==true){
//if nothing is above the object, stop slidding
if (Physics.Raycast(this.gameObject.transform.position, up, out ray, 5f) == false)
{
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x - 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = false;
charController.height = 2.0f;
playerStats.Traction = orignalTraction;
}
else
{
Debug.Log("Object above you");
}
}
}
}

View File

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

View File

@@ -32,6 +32,7 @@ public class WallRun : MonoBehaviour
float elapsedTimeSinceWallAttach = 0;
float elapsedTimeSinceWallDetatch = 0;
bool jumping;
private bool regainedJump = false;
bool isPlayergrounded() => playerMovementController.isGrounded;
@@ -111,11 +112,17 @@ public class WallRun : MonoBehaviour
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
if (elapsedTimeSinceWallAttach > 0.125f && regainedJump == false)//Allows players to always jump off of walls
{
regainedJump = true;
playerMovementController.decrementCurrentJumpNumber();
}
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
regainedJump = false;
}
}
@@ -147,8 +154,9 @@ public class WallRun : MonoBehaviour
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() *Time.deltaTime;// * wallSpeedMultiplier;
moveToSet.y = 0;
Vector3 cancelDrop = new Vector3(0, 0.01f, 0);
playerMovementController.SetPlayerVelocity(moveToSet);
playerMovementController.AddPlayerVelocity(cancelDrop);
//Debug.Log("On Wall");
isWallRunning = true;
}

View File

@@ -1,7 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
}

View File

@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
private Vector3 rad;
void Start ()
{
rad = (transform.position - player.transform.position);
}
void Update ()
{
offset = transform.parent.forward * rad.magnitude;
transform.position = new Vector3((player.transform.position.x - offset.x),((player.transform.position.y - offset.y)+2),(player.transform.position.z - offset.z));
}
}

View File

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

View File

@@ -13,7 +13,7 @@ public class PlayerInventory : MonoBehaviour
void Awake(){
pStats = GetComponent<PlayerStats>();
DontDestroyOnLoad(this.gameObject);
DontDestroyOnLoad(transform.parent.gameObject);
}
@@ -21,7 +21,7 @@ public class PlayerInventory : MonoBehaviour
if(!items.Contains(item) && ableToAdd){
Debug.Log("Item Added");
items.Add(item);
item.Equip(pStats);
item.Equip(pStats, this.gameObject);
}
else if(!ableToAdd && !items.Contains(item)){
Debug.Log("Item Cannot Be Added");
@@ -30,7 +30,6 @@ public class PlayerInventory : MonoBehaviour
Debug.Log("Item Removed");
RemoveItem(item);
}
}
public void AddSpecialItem<T>(T itemCandidate) { // Unless we don't want the four special items to be handled by inventory/inventory manager?
@@ -42,7 +41,7 @@ public class PlayerInventory : MonoBehaviour
public void RemoveItem(Item item){
if(items.Remove(item)){
item.Unequip(pStats);
item.Unequip(pStats, this.gameObject);
}
}

View File

@@ -1,9 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
public class PlayerMovement : NetworkBehaviour
{
//Scripts
@@ -18,19 +19,23 @@ public class PlayerMovement : MonoBehaviour
private Vector3 moveX;
private Vector3 driftVel;
//Player prefab
private GameObject parentObj;
//Character Moving
private CharacterController moveController;
//Jump value
private int curJumpNum;
private bool jumpPressed;
bool tempSet = false;
float tempTraction = 0.0f;
//Jump physics
private float mass = 5.0F; // defines the character mass
private Vector3 impact = Vector3.zero;
private float distToGround;
//Wallrunning
private WallRun wallRun;
@@ -43,7 +48,6 @@ public class PlayerMovement : MonoBehaviour
private Ray groundRay;
private RaycastHit groundHit;
//Camera Variables
private LayerMask ignoreP;
private Vector3 camRotation;
@@ -56,49 +60,68 @@ public class PlayerMovement : MonoBehaviour
[Range(50, 500)]
public int sensitivity = 200;
//Blink Variables
private LineRenderer beam;
private Vector3 origin;
private Vector3 endPoint;
private Vector3 mousePos;
private RaycastHit hit;
/////
//Ragdoll variables
private Vector3 hit;
private Rigidbody rB;
private CapsuleCollider capCol;
private bool firstHit = false;
private bool heldDown = false;
private bool beginRagTimer = false;
private float ragTime;
private Vector3 prevRot;
private Vector3 hitForce;
//Slide Variables
private bool isSliding = false;
private float originalTraction;
private RaycastHit ray;
private Vector3 up;
private bool qDown;
//Kick Variables
void Awake()
{
//Initialize Components
moveController = GetComponent<CharacterController>();
rB = GetComponent<Rigidbody>();
capCol = GetComponent<CapsuleCollider>();
pStats = GetComponent<PlayerStats>();
ignoreP = LayerMask.GetMask("Player");
beam = gameObject.AddComponent<LineRenderer>();
beam.startWidth = 0.2f;
beam.endWidth = 0.2f;
beam.enabled = false;
parentObj = transform.parent.gameObject;
//camera transform
cam = GetComponentInChildren<Camera>();
cam = parentObj.GetComponentInChildren<Camera>();
capCol.enabled = false;
//Wallrun
//wallRun = gameObject.GetComponent<WallRun>();
wallRun = gameObject.GetComponent<WallRun>();
up = this.gameObject.GetComponentInParent<Transform>().up;
}
void Start()
{
distToGround = GetComponent<Collider>().bounds.extents.y;
// 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;
}
// 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
Rotate();
Rotation();
if(moveController.enabled == true){
@@ -110,18 +133,39 @@ public class PlayerMovement : MonoBehaviour
// consumes the impact energy each cycle:
impact = Vector3.Lerp(impact, Vector3.zero, 5*Time.deltaTime);
Blink();
}
else{
Debug.Log("MoveController is either Disabled or wasn't retrieved correctly");
if (RagdollTimer() == 0){
firstHit = false;
DisableRagdoll();
}
//Gravity without moveController
vel.y -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,vel.y,0));
//Debug.LogWarning("MoveController is either Disabled or wasn't retrieved correctly");
}
//TESTING RAGDOLL STUFF NEEDS SOME WORK
//Checks if player should respawn
//Respawn();
if (Input.GetMouseButton(1) && heldDown == false){
getHit(new Vector3(vel.x, 0, vel.z), 30);
heldDown = true;
}
if(!Input.GetMouseButton(1)){
heldDown = false;
}
//Checks if player should respawn
Respawn();
}
@@ -145,9 +189,13 @@ public class PlayerMovement : MonoBehaviour
Gravity();
driftVel = Vector3.Lerp(driftVel, vel, pStats.Traction * Time.deltaTime);
//Moving outside basic wasd
//Jump Function
Jump();
//Slide Function
Slide();
moveController.Move(driftVel);
}
@@ -157,7 +205,7 @@ public class PlayerMovement : MonoBehaviour
public float PlayerSpeed()
{
//If nothing is pressed speed is 0
if (Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f)
if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f) || isSliding)
{
pStats.CurVel = 0.0f;
return pStats.CurVel;
@@ -198,7 +246,7 @@ public class PlayerMovement : MonoBehaviour
private void Jump()
{
//If space is pressed apply an upwards force to the player
if (Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum + 1 < pStats.JumpNum)
if (Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum + 1 < pStats.JumpNum && !isSliding)
{
AddImpact(transform.up, pStats.JumpPow);
curJumpNum++;
@@ -207,8 +255,6 @@ public class PlayerMovement : MonoBehaviour
lastTimeJumped = Time.time;
//NEEDS TO BE MASSIVELY CHANGE LIKELY USE RAYCAST TO CHECK IF ACTUALLY ON GROUND
//CANNOT USE CHARACTERCONTROLLER.ISGROUNDED IT IS UNRELIABLE
//If grounded no jumps have been used
if(isGrounded){
curJumpNum = 0;
@@ -218,6 +264,9 @@ public class PlayerMovement : MonoBehaviour
if (Input.GetAxis("Jump") == 0) jumpPressed = false;
}
//PlayerScript
public bool GetJumpPressed(){
return jumpPressed;
}
@@ -237,15 +286,33 @@ public class PlayerMovement : MonoBehaviour
vel = newVelocity;
}
//Camera
private void Rotate()
//Camera and Player Rotation
public void decrementCurrentJumpNumber()
{
transform.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
curJumpNum--;
}
//Camera
private void Rotation()
{
Vector3 lastCamPos = new Vector3(0,0,0);
Vector3 rotOffset = transform.localEulerAngles;
if(moveController.enabled){
transform.parent.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
camRotation.x -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
camRotation.x = Mathf.Clamp(camRotation.x, minAngle, maxAngle);
cam.transform.localEulerAngles = camRotation;
}
/*
else{
cam.transform.localEulerAngles = cam.transform.localEulerAngles - rotOffset;
}
*/
}
@@ -260,13 +327,12 @@ public class PlayerMovement : MonoBehaviour
}
}
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void Gravity(){
//Temp Values for Glider
float tempTraction = 0.0f;
bool tempSet = false;
//ADD CHECKER FOR GLIDER WHEN FULLY IMPLEMENTED
//Gliding
if(jumpPressed && pStats.HasGlider){
vel.y -= (pStats.PlayerGrav-18) * Time.deltaTime;
@@ -275,7 +341,6 @@ public class PlayerMovement : MonoBehaviour
pStats.Traction = 1.0f;
tempSet = true;
}
}
else{
@@ -287,13 +352,15 @@ public class PlayerMovement : MonoBehaviour
//Normal Gravity
vel.y -= pStats.PlayerGrav * Time.deltaTime;
}
//Wallrunning
if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
//If gliding
//Go down slowly
}
void GroundCheck()
{
// Make sure that the ground check distance while already in air is very small, to prevent suddenly snapping to ground
@@ -316,63 +383,101 @@ public class PlayerMovement : MonoBehaviour
}
}
//ADJUST SO DISTANCE IS DETERMINED BY SCROLL WHEEL
//blinks the player forwards
private void Blink()
{
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;
//Ragdoll Functions
private void getHit(Vector3 dir, float force){
if(firstHit == false){
EnableRagdoll();
dir.Normalize();
rB.AddForce(dir * force, ForceMode.Impulse);
firstHit = true;
}
}
private void EnableRagdoll(){
ragTime = pStats.RecovTime;
prevRot = transform.localEulerAngles;
capCol.enabled = true;
moveController.enabled = false;
rB.isKinematic = false;
rB.detectCollisions = true;
}
// 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);
}*/
private void DisableRagdoll(){
capCol.enabled = false;
moveController.enabled = true;
rB.isKinematic = true;
rB.detectCollisions = false;
transform.localEulerAngles = prevRot;
}
//When to begin the ragdoll timer
private float RagdollTimer(){
if(beginRagTimer == false){
beginRagTimer = Physics.Raycast(transform.position, -Vector3.up, distToGround + 1f);
}
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)
else if(ragTime <= 0){
ragTime = 0;
beginRagTimer = false;
}
if(beginRagTimer == true){
ragTime -= Time.deltaTime;
}
return ragTime;
}
//Slide Function
private void Slide(){
if (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;
moveController.height = 1.0f;
pStats.Traction = 0.01f;
}
pStats.Traction += .02f;
}
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 slidding
if (Physics.Raycast(this.gameObject.transform.position, up, out ray, 5f) == false)
{
transform.position = endPoint + hit.normal * 1.25f;
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x + 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = false;
moveController.height = 2.0f;
pStats.Traction = originalTraction;
}
else{
Debug.Log("Object above you");
}
}
//if button is not held down, and still slidding (if they let go but something was above them) check to see if something is still above them, if not
else if (Input.GetKey(KeyCode.Q) == false && isSliding==true){
//if nothing is above the object, stop slidding
if (Physics.Raycast(this.gameObject.transform.position, up, out ray, 5f) == false)
{
this.gameObject.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x - 90, this.transform.eulerAngles.y, this.transform.eulerAngles.z);
isSliding = false;
moveController.height = 2.0f;
pStats.Traction = originalTraction;
}
//if teleporting in the air or something, just spawn at endpoint
else
{
Debug.Log("Object above you");
transform.position = endPoint;
}
//reenable character controller
}
}
}

View File

@@ -1,11 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
public class PlayerStats : MonoBehaviour
{
//Maximum possible player speed
[SerializeField]
private float maxVel = 25.0f;
public float MaxVel{
get{ return maxVel; }
@@ -13,7 +13,6 @@ public class PlayerStats : MonoBehaviour
}
//Minimum possible player speed
[SerializeField]
private float minVel = 2.0f;
public float MinVel{
get{ return minVel; }
@@ -21,15 +20,13 @@ public class PlayerStats : MonoBehaviour
}
//Current player speed
[SerializeField]
private float curVel = 0.0f;
public float CurVel{
get{ return curVel; }
set{ curVel = value; }
}
//Player Jump power
[SerializeField]
//Player Acceleration
private float acc = 0.1f;
public float Acc{
get{ return acc; }
@@ -37,7 +34,6 @@ public class PlayerStats : MonoBehaviour
}
//Player Jump power
[SerializeField]
private float jumpPow = 300.0f;
public float JumpPow{
get{ return jumpPow; }
@@ -45,7 +41,6 @@ public class PlayerStats : MonoBehaviour
}
//Players Number of Jumps
[SerializeField]
private int jumpNum = 2; ////// UPDATE TO 2 WHEN THE JUMP ISSUE IS FIXED
public int JumpNum{
get{ return jumpNum; }
@@ -53,7 +48,6 @@ public class PlayerStats : MonoBehaviour
}
//Player Traction
[SerializeField]
private float traction = 3.0f;
public float Traction{
get{ return traction; }
@@ -61,7 +55,6 @@ public class PlayerStats : MonoBehaviour
}
//Player Kick Power
[SerializeField]
private float kickPow;
public float KickPow{
get{ return kickPow; }
@@ -69,8 +62,7 @@ public class PlayerStats : MonoBehaviour
}
//Player Recovery Time When Knocked Down
[SerializeField]
private float recovTime;
private float recovTime = 3.0f;
public float RecovTime{
get{ return recovTime; }
set{ recovTime = value; }
@@ -78,7 +70,6 @@ public class PlayerStats : MonoBehaviour
//MAY BE UNNECCESARY DEPENDING ON HOW GLIDER TURNS OUT
//Gravity Affecting the player
[SerializeField]
private float playerGrav = 20.0f;
public float PlayerGrav{
get{ return playerGrav; }
@@ -86,7 +77,6 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Blink
[SerializeField]
private bool hasBlink = false;
public bool HasBlink{
get{ return hasBlink; }
@@ -94,7 +84,6 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Glider
[SerializeField]
private bool hasGlider = false;
public bool HasGlider{
get{ return hasGlider; }
@@ -102,7 +91,6 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Grapple
[SerializeField]
private bool hasGrapple = false;
public bool HasGrapple{
get{ return hasGrapple; }
@@ -110,7 +98,6 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Wallrun
[SerializeField]
private bool hasWallrun = false;
public bool HasWallrun{
get{ return hasWallrun; }
@@ -118,7 +105,6 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Nitro
[SerializeField]
private bool hasNitro = false;
public bool HasNitro{
get{ return hasNitro; }
@@ -126,17 +112,33 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Dash
[SerializeField]
private bool hasDash = false;
private bool hasDash;
public bool HasDash{
get{ return hasDash; }
set{ hasDash = value; }
}
[SerializeField]
private int playerPoints = 15;
public int PlayerPoints{
get{ return playerPoints; }
set{ playerPoints = value; }
}
void Update(){
VariableValidation();
}
void VariableValidation(){
Debug.Assert((maxVel >= 0), "maxVel cannot be below zero");
Debug.Assert((minVel >= 0), "minVel cannot be below zero");
Debug.Assert((curVel >= 0), "curVel cannot be below zero");
Debug.Assert((jumpPow >= 0), "jumpPow cannot be below zero");
Debug.Assert((jumpNum >= 2), "jumpNum cannot be below zero");
Debug.Assert((traction >= 0), "traction cannot be below zero");
//Debug.Assert((kickPow >= 0), "Playerpoints cannot be below zero");
Debug.Assert((recovTime >= 0), "recovTime cannot be below zero");
Debug.Assert((playerGrav >= 0), "playerGrav cannot be below zero");
Debug.Assert((playerPoints >= 0), "Playerpoints cannot be below zero");
}
}

View File

@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Setup : MonoBehaviour
{
private PlayerStats pstats;
public bool hasWallRun;
[Range( 1, 50)]
public float maxSpeed;
// Start is called before the first frame update
void Start()
{
pstats = this.gameObject.GetComponent<PlayerStats>();
pstats.HasWallrun = hasWallRun;
pstats.MaxVel = maxSpeed;
}
}