Updated PlayerPrefab

Implemented Slide into player
Added CamFollow
This commit is contained in:
Melbyj1125
2021-11-01 12:15:17 -05:00
parent 45a2c5b473
commit 63e2318252
9 changed files with 354 additions and 218 deletions

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

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

View File

@@ -18,6 +18,9 @@ public class PlayerMovement : MonoBehaviour
private Vector3 moveX;
private Vector3 driftVel;
//Player prefab
private GameObject parentObj;
//Character Moving
private CharacterController moveController;
@@ -67,6 +70,15 @@ public class PlayerMovement : MonoBehaviour
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
@@ -74,13 +86,16 @@ public class PlayerMovement : MonoBehaviour
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>();
up = this.gameObject.GetComponentInParent<Transform>().up;
}
void Start()
@@ -137,8 +152,6 @@ public class PlayerMovement : MonoBehaviour
//Checks if player should respawn
Respawn();
}
@@ -162,9 +175,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);
}
@@ -174,7 +191,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;
@@ -215,7 +232,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++;
@@ -261,14 +278,21 @@ public class PlayerMovement : MonoBehaviour
private void Rotation()
{
Vector3 lastCamPos = new Vector3(0,0,0);
Vector3 rotOffset = transform.localEulerAngles;
if(moveController.enabled){
transform.Rotate(Vector3.up * sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
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;
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;
}
*/
}
@@ -368,7 +392,7 @@ public class PlayerMovement : MonoBehaviour
//When to begin the ragdoll timer
private float RagdollTimer(){
if(beginRagTimer == false){
beginRagTimer = Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f);
beginRagTimer = Physics.Raycast(transform.position, -Vector3.up, distToGround + 1f);
}
else if(ragTime <= 0){
@@ -383,6 +407,57 @@ public class PlayerMovement : MonoBehaviour
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 = 5;
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");
}
}