Merge branch 'rigidBodySetup'

This commit is contained in:
Melbyj1125
2021-11-01 12:21:31 -05:00
17 changed files with 484 additions and 266 deletions

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

@@ -13,8 +13,7 @@ public class SpecialItem : Item
public bool hasNitroM;
public bool hasDashM;
public float cooldownM;
//public MonoScript scriptM;
public override void Equip(PlayerStats p, GameObject player){
if(maxVelM != 0){
p.MaxVel += maxVelM;
@@ -61,9 +60,6 @@ public class SpecialItem : Item
if(hasDashM != false){
p.HasDash = hasDashM;
}
/*if(scriptM != null){
player.AddComponent(scriptM.GetClass());
}*/
}
public override void Unequip(PlayerStats p, GameObject player){
@@ -112,9 +108,7 @@ public class SpecialItem : Item
if(hasDashM != false){
p.HasDash = false;
}
/*if(scriptM != null){
Destroy(player.GetComponent(scriptM.GetClass()));
}*/
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
//Mote: This should be refactored at some point
public class Slide : MonoBehaviour{
//this may be deprecated at some poiint later in development if we start ussing a rigid bod
public Camera playerCam;
private bool isSliding = false;
private CharacterController charController;
@@ -11,10 +11,7 @@ public class Slide : MonoBehaviour{
private float orignalTraction;
private RaycastHit ray;
private Vector3 up;
// Start is called before the first frame update
void Start(){
}
private void Awake(){
charController = this.gameObject.GetComponentInParent<CharacterController>();
playerStats = this.gameObject.GetComponentInParent<PlayerStats>();

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

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c2c2e0314365de34c923bb88c9b334ca
guid: 394466212a506df4da8f22e46bd4e333
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -13,7 +13,7 @@ public class PlayerInventory : MonoBehaviour
void Awake(){
pStats = GetComponent<PlayerStats>();
DontDestroyOnLoad(this.gameObject);
DontDestroyOnLoad(transform.parent.gameObject);
}
@@ -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?

View File

@@ -19,6 +19,9 @@ public class PlayerMovement : NetworkBehaviour
private Vector3 moveX;
private Vector3 driftVel;
//Player prefab
private GameObject parentObj;
//Character Moving
private CharacterController moveController;
@@ -63,9 +66,20 @@ public class PlayerMovement : NetworkBehaviour
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
@@ -73,13 +87,16 @@ public class PlayerMovement : NetworkBehaviour
rB = GetComponent<Rigidbody>();
capCol = GetComponent<CapsuleCollider>();
pStats = GetComponent<PlayerStats>();
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()
@@ -103,6 +120,7 @@ public class PlayerMovement : NetworkBehaviour
// Otherwise we let the server handle moving us
if (!IsLocalPlayer) { return; }
//Controls for camera
Rotation();
@@ -119,7 +137,7 @@ public class PlayerMovement : NetworkBehaviour
}
else{
if (rB.velocity.magnitude < 0.2f){
if (RagdollTimer() == 0){
firstHit = false;
DisableRagdoll();
@@ -147,8 +165,6 @@ public class PlayerMovement : NetworkBehaviour
//Checks if player should respawn
Respawn();
}
@@ -172,9 +188,13 @@ public class PlayerMovement : NetworkBehaviour
Gravity();
driftVel = Vector3.Lerp(driftVel, vel, pStats.Traction * Time.deltaTime);
//Moving outside basic wasd
//Jump Function
Jump();
//Slide Function
Slide();
moveController.Move(driftVel);
}
@@ -184,7 +204,7 @@ public class PlayerMovement : NetworkBehaviour
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;
@@ -225,7 +245,7 @@ public class PlayerMovement : NetworkBehaviour
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++;
@@ -270,12 +290,22 @@ public class PlayerMovement : NetworkBehaviour
//Camera and Player Rotation
private void Rotation()
{
transform.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
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;
}
*/
}
@@ -356,20 +386,91 @@ public class PlayerMovement : NetworkBehaviour
}
}
private void EnableRagdoll(){
prevRot = transform.localEulerAngles;
capCol.enabled = true;
moveController.enabled = false;
rB.isKinematic = false;
rB.detectCollisions = true;
ragTime = pStats.RecovTime;
prevRot = transform.localEulerAngles;
capCol.enabled = true;
moveController.enabled = false;
rB.isKinematic = false;
rB.detectCollisions = true;
}
private void DisableRagdoll(){
capCol.enabled = false;
moveController.enabled = true;
rB.isKinematic = true;
rB.detectCollisions = false;
transform.localEulerAngles = prevRot;
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(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)
{
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;
}
else
{
Debug.Log("Object above you");
}
}
}
}

View File

@@ -26,7 +26,7 @@ public class PlayerStats : MonoBehaviour
set{ curVel = value; }
}
//Player Jump power
//Player Acceleration
private float acc = 0.1f;
public float Acc{
get{ return acc; }
@@ -62,7 +62,7 @@ public class PlayerStats : MonoBehaviour
}
//Player Recovery Time When Knocked Down
private float recovTime;
private float recovTime = 3.0f;
public float RecovTime{
get{ return recovTime; }
set{ recovTime = value; }
@@ -112,7 +112,7 @@ public class PlayerStats : MonoBehaviour
}
//If The Player Has Dash
private bool hasDash = false;
private bool hasDash;
public bool HasDash{
get{ return hasDash; }
set{ hasDash = value; }
@@ -124,12 +124,21 @@ public class PlayerStats : MonoBehaviour
set{ playerPoints = value; }
}
// void Update(){
// VariableValidation();
// }
void Update(){
VariableValidation();
}
// void VariableValidation(){
// Debug.Assert((playerPoints != null && playerPoints > 0), "Not valid value");
// }
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;
}
}

View File

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