Merge branch 'main' into KingImp

This commit is contained in:
Katherine
2021-12-10 14:15:04 -06:00
282 changed files with 44730 additions and 3387 deletions

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -6,20 +7,25 @@ public class Archer : MonoBehaviour
{
//current target ponting at
private Transform target;
public float rotationSpeed = 10f;
//range of turrent
[Header("Attributes")]
//range of turret
public float range = 20.0f;
//how fast and how much time before the next shot
public float fireRate = 4.0f;
private float shootingCooldown = 2.0f;
private float shootingCooldown = 1.0f;
[Header("Unity Setup Fields")]
public string runnerTag = "Player"; //tags the player;
public Transform partToRotate;
public float rotationSpeed = 10f;
public GameObject ArrowPrefab;
public Transform firePoint;
[SerializeField] GameObject[] runners;
// Start is called before the first frame update
void Start()
@@ -34,7 +40,7 @@ public class Archer : MonoBehaviour
//cycles through all enemies within range, the closest one, and sets the target at.
//not done every frame
GameObject[] runners = GameObject.FindGameObjectsWithTag(runnerTag);
runners = GameObject.FindGameObjectsWithTag(runnerTag);
//temp variable for the shortest distance for an runner
float shortestDistance = Mathf.Infinity;
@@ -44,6 +50,8 @@ public class Archer : MonoBehaviour
foreach(GameObject runner in runners)
{
//Debug.Log(runners.Length);
float distanceToRunner = Vector3.Distance(transform.position, runner.transform.position);
if(distanceToRunner < shortestDistance)
@@ -55,7 +63,8 @@ public class Archer : MonoBehaviour
if(nearestRunner != null && shortestDistance <= range)
{
target = nearestRunner.transform;
target = nearestRunner.transform; //adding in the players rotation and momentum.
//leads the shots here
}
else
{
@@ -77,8 +86,32 @@ public class Archer : MonoBehaviour
Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime *rotationSpeed).eulerAngles;
partToRotate.rotation = Quaternion.Euler (0f, rotation.y, 0f);
if (shootingCooldown <= 0f)
{
Shoot();
shootingCooldown = 1f/ fireRate;
}
shootingCooldown -= Time.deltaTime;
}
void Shoot()
{
GameObject arrowGO = (GameObject)Instantiate (ArrowPrefab, firePoint.position, firePoint.rotation);
Arrow arrow = arrowGO.GetComponent<Arrow>();
if (arrow != null)
{
arrow.Seek(target.position);
}
}
void OnDrawGizmosSelected()
{

View File

@@ -0,0 +1,59 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using UnityEngine;
public class Arrow : MonoBehaviour
{
private UnityEngine.Vector3 target;
private bool isLive=false;
public float speed = 90f;
//finds targed
public void Seek(UnityEngine.Vector3 _target)
{
//can also do effects, speed on the bullet, damage amount, etc.
target = _target;
isLive = true;
}
// Update is called once per frame
void Update()
{
if (target == null)
{
//Destroy(gameObject);
return;
}
if (isLive)
{
UnityEngine.Vector3 dir = target - transform.position;
//distance
float distanceThisFrame = speed * Time.deltaTime;
//checking from current distance to current target
if (dir.magnitude <= distanceThisFrame)
{
HitTarget();
return;
}
//move in the worldspace
transform.Translate(dir.normalized * distanceThisFrame, Space.World);
}
}
//logic for hitting something
void HitTarget()
{
isLive=false;
Destroy(gameObject);
}
}

View File

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

View File

@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BreakableBlock : MonoBehaviour
{
//kicking power 150 (250 for stornger kick)
public float health;
// Start is called before the first frame update
void Start(){
//if health is not set, default it to 1
if(health == 0){
health = 3;
}
}
// Update is called once per frame
void Update()
{
}
public void damage(float kickPower){
int totalDamage = (int)(kickPower / 50.0);
health -= totalDamage;
Debug.Log(health);
//if item is at 0 health
if(health <= 0){
destroy();
}
}
//called once health here is zero
public void destroy(){
Destroy(this.gameObject);
}
}

View File

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

View File

@@ -0,0 +1,94 @@
using MLAPI;
using MLAPI.Messaging;
using MLAPI.SceneManagement;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EndCollider : NetworkBehaviour {
// When player collides with the trigger for the end zone
private void OnTriggerEnter(Collider other) {
if (other.gameObject.transform.parent.gameObject.GetComponent<NetworkObject>().OwnerClientId == NetworkManager.Singleton.LocalClientId) {
RunnerFinishedMapServerRPC();
}
}
[ServerRpc(RequireOwnership = false)]
private void RunnerFinishedMapServerRPC(ServerRpcParams serverRpcParams = default) {
// Get all players in the scene
GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player");
// Find our player first
foreach (GameObject character in playableCharacters) {
if (character.GetComponent<NetworkObject>().OwnerClientId == serverRpcParams.Receive.SenderClientId) {
// Player found
// Despawn them
character.GetComponent<NetworkObject>().Despawn(true);
// Update the player data such that Finished is true
if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(serverRpcParams.Receive.SenderClientId, out string clientGuid)) {
ServerGameNetPortal.Instance.clientData[clientGuid] = new PlayerData(
ServerGameNetPortal.Instance.clientData[clientGuid].PlayerName,
ServerGameNetPortal.Instance.clientData[clientGuid].ClientId,
ServerGameNetPortal.Instance.clientData[clientGuid].IsKing,
true
);
}
}
}
//todo: Check if all runners are finished
bool allFinished = true;
foreach (PlayerData pData in ServerGameNetPortal.Instance.clientData.Values) {
// Make sure we don't check the king, since the value of Finished will always be false
if (pData.IsKing != true) {
// If one player isn't finished, then set allFinished to false
if (pData.Finished != true) {
allFinished = false;
}
}
}
if (allFinished) {
// Go to the post game screen
NetworkSceneManager.SwitchScene("PostGame");
} else {
// Loop over all characters
foreach (GameObject character in playableCharacters) {
// Make sure we find the characters that aren't the one that just finished (subsequently calling the rpc)
if (character.GetComponent<NetworkObject>().OwnerClientId != serverRpcParams.Receive.SenderClientId) {
// Then grab their GUID
if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(serverRpcParams.Receive.SenderClientId, out string clientGuid)) {
// To verify they aren't the king
if (ServerGameNetPortal.Instance.clientData[clientGuid].IsKing != true) {
// Then call a client rpc to the finished player to enable the camera locally
ClientRpcParams clientRpcParams = new ClientRpcParams {
Send = new ClientRpcSendParams {
TargetClientIds = new ulong[] { serverRpcParams.Receive.SenderClientId }
}
};
EnableSpectatorCameraClientRPC(character.GetComponent<NetworkObject>().OwnerClientId, clientRpcParams);
}
}
}
}
}
}
[ClientRpc]
private void EnableSpectatorCameraClientRPC(ulong otherRunnerClientID, ClientRpcParams clientRpcParams = default) {
GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject character in playableCharacters) {
if (character.GetComponent<NetworkObject>().OwnerClientId == otherRunnerClientID) {
GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<Camera>().enabled = true;
GameHandler.FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<AudioListener>().enabled = true;
}
}
GameObject.FindGameObjectWithTag("RunnerHUD").GetComponent<PlayerHUD>().spectating_text.text = "SPECTATING";
}
}

View File

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

View File

@@ -11,31 +11,12 @@ public class PlayerHUD : NetworkBehaviour
[SerializeField] private int raceTimer;
public TMP_Text countdown_text;
public GameObject RunnerHUD;
public GameObject KingHUD;
public TMP_Text spectating_text;
// Start is called before the first frame update
void Start() {
countdown_text.text = "Time Remaining: 00:00";
StartCoroutine(RaceTimeCountdown());
// Get all players in the scene
GameObject[] playableCharacters = GameObject.FindGameObjectsWithTag("Player");
// Find our player and enable their hud respectively
foreach (GameObject character in playableCharacters) {
if (character.GetComponent<NetworkObject>().OwnerClientId == NetworkManager.Singleton.LocalClientId) {
if (ServerGameNetPortal.Instance.clientIdToGuid.TryGetValue(NetworkManager.Singleton.LocalClientId, out string clientGuid)) {
if (ServerGameNetPortal.Instance.clientData.TryGetValue(clientGuid, out PlayerData playerData)) {
if (playerData.IsKing) {
KingHUD.SetActive(true);
} else {
RunnerHUD.SetActive(true);
}
}
}
}
}
}
IEnumerator RaceTimeCountdown() {

View File

@@ -4,15 +4,17 @@ using UnityEngine;
public class Bumper : MonoBehaviour {
public float bumpPower = 30;
// Is called whenever something collides with the bumper
void OnTriggerEnter(Collider other) {
Debug.Log("Bump!");
if (other.tag == "Player") {//Checks if the other object is the player
float DirBumpX = other.GetComponent<dPlayerMovement>().vel.x * -1;//Inverts the Player Velocity x
float DirBumpZ = other.GetComponent<dPlayerMovement>().vel.z * -1;//Inverts the Player Velocity y
Vector3 DirBump = new Vector3(DirBumpX, .01f, DirBumpZ);//Creates a direction to launch the player
void OnTriggerEnter(Collider objectHit) {
if (objectHit.tag == "Player") {//Checks if the other object is the player
dPlayerMovement playerMovement = objectHit.GetComponent<dPlayerMovement>();
float DirBumpX = playerMovement.vel.x * -1;//Inverts the Player Velocity x
float DirBumpZ = playerMovement.vel.z * -1;//Inverts the Player Velocity y
Vector3 DirBump = new Vector3(DirBumpX, .1f, DirBumpZ);//Creates a direction to launch the player
DirBump = Vector3.Normalize(DirBump);//Normalizes the vector to be used as a bump direction
other.GetComponent<dPlayerMovement>().GetHit(DirBump, 50); //Launches tthe player directly away from the bumper
playerMovement.GetHit(DirBump, bumpPower); //Launches tthe player directly away from the bumper
}
}
}

View File

@@ -35,7 +35,10 @@ public class GameHandler : NetworkBehaviour
foreach (GameObject character in playableCharacters) {
if (character.GetComponent<NetworkObject>().OwnerClientId == NetworkManager.Singleton.LocalClientId) {
localPlayer = character;
FindGameObjectInChildWithTag(character, "PlayerCam").SetActive(true);
FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<Camera>().enabled = true;
FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<AudioListener>().enabled = true;
FindGameObjectInChildWithTag(character, "PlayerCam").GetComponent<PlayerCam>().enabled = true;
}
}
@@ -63,7 +66,7 @@ public class GameHandler : NetworkBehaviour
}
// Only works for 1st generation children
private static GameObject FindGameObjectInChildWithTag(GameObject parent, string tag) {
public static GameObject FindGameObjectInChildWithTag(GameObject parent, string tag) {
Transform t = parent.transform;
for (int i = 0; i < t.childCount; i++) {

View File

@@ -5,11 +5,14 @@ public struct PlayerData {
public bool IsKing { get; set; }
public PlayerInventory pInv{get; set;}
public PlayerData(string playerName, ulong clientId, bool isKing = false)
public bool Finished { get; set; }
public PlayerData(string playerName, ulong clientId, bool isKing = false, bool finished = false)
{
PlayerName = playerName;
pInv = new PlayerInventory();
ClientId = clientId;
IsKing = isKing;
Finished = finished;
}
}

View File

@@ -16,13 +16,19 @@ public class dDash : NetworkBehaviour{
float dashSpeed = 12;
CharacterController characterController;
dPlayerMovement pMove;
void Start(){
characterController = this.gameObject.GetComponent<CharacterController>();
pMove = GetComponent<dPlayerMovement>();
}
//UPDATE CHECK FOR MOVEMENT ONLY WHEN DASHING
void FixedUpdate(){
if(pMove.pStats.HasDash) Dash();
}
void Dash(){
//if (!IsLocalPlayer) { return; }
if(characterController.enabled == true){
if (Input.GetKeyDown(KeyCode.E) && isOnCoolDown == false)

View File

@@ -84,9 +84,9 @@ public class dGrapplingHook : NetworkBehaviour
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength)
{
//Impact Based
playerMovement.AddImpact((hookPoint.transform.position - gameObject.transform.position), pStats.PlayerGrav);
//playerMovement.AddImpact((hookPoint.transform.position - gameObject.transform.position), pStats.PlayerGrav*2);
//Character controller move?
//movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength*Time.deltaTime);
movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength * 10 *Time.deltaTime);
//Lerp? or another smoother way? Better physics? Wait until refinement to deal with
}
}

View File

@@ -12,12 +12,12 @@ public class dKickController : NetworkBehaviour
//slightly bad practice, when merging find a better work around
private bool isDiveKicking = false;
private CharacterController characterController;
public dPlayerMovement pMove;
public PlayerStats pStats;
void Start(){
pStats = GetComponent<PlayerStats>();
pMove = GetComponent<dPlayerMovement>();
characterController = this.gameObject.GetComponent<CharacterController>();
leg = transform.GetChild(0).gameObject;
leg.SetActive(false);
@@ -31,7 +31,7 @@ public class dKickController : NetworkBehaviour
//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 && characterController.isGrounded == false)
if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isGrounded == false)
{
Debug.Log("dive");
// if kicking in air, kick until grounded (maybe add some foward momentum if needeD)
@@ -41,12 +41,11 @@ public class dKickController : NetworkBehaviour
}
//otherwise do ground kick for .3 seconds
else if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false){
Debug.Log("kick");
StartCoroutine(Kicking(.3f));
}
//once dive kick touches ground, set back to normal state
if (characterController.isGrounded == true && isDiveKicking == true)
if (pMove.isGrounded == true && isDiveKicking == true)
{
isDiveKicking = false;
isKicking = false;
@@ -76,6 +75,9 @@ public class dKickController : NetworkBehaviour
Debug.Log(direction);
collision.rigidbody.AddForce(direction * pStats.KickPow, ForceMode.Impulse);
}
if (collision.transform.CompareTag("destroyable") && myCollider == leg.GetComponent<Collider>()){
collision.transform.gameObject.GetComponent<BreakableBlock>().damage(pStats.KickPow);
}
}
}

View File

@@ -112,13 +112,11 @@ public class dWallRun : NetworkBehaviour
{
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * playerMovementController.pStats.PlayerGrav * Time.deltaTime));
}
}

View File

@@ -18,6 +18,7 @@ public class dPlayerMovement : NetworkBehaviour
private Vector3 moveZ;
private Vector3 moveX;
private Vector3 driftVel;
private Vector3 lerpY;
//Player prefab
private GameObject parentObj;
@@ -26,12 +27,19 @@ public class dPlayerMovement : NetworkBehaviour
private CharacterController moveController;
//Jump value
public int curJumpNum;
private bool jumpPressed;
public int curJumpNum; // current Jumps used
private bool jumpHeld; // Is jump being held
float coyJumpTimer = 0.1f; // Default Coyote Jump time
float curCoyJumpTimer; // current Coyote Jump time
public float lowJumpMultiplier; // Short jump multiplier
public float fallMultiplier; // High Jump Multiplier
private float g = 0; // the y velocity
//Glide Values
bool tempSet = false;
float tempTraction = 0.0f;
//Jump physics
//Impact physics
private float mass = 5.0F; // defines the character mass
private Vector3 impact = Vector3.zero;
private float distToGround;
@@ -49,7 +57,6 @@ public class dPlayerMovement : NetworkBehaviour
private RaycastHit groundHit;
//Camera Variables
private LayerMask ignoreP;
private Vector3 camRotation;
public Camera cam;
@@ -80,23 +87,31 @@ public class dPlayerMovement : NetworkBehaviour
//Blink
private dBlink blink;
//Animation controller
Animator animator;
void Awake()
{
//Initialize Components
moveController = GetComponent<CharacterController>();
rB = GetComponent<Rigidbody>();
capCol = GetComponent<CapsuleCollider>();
pStats = GetComponent<PlayerStats>();
parentObj = transform.parent.gameObject;
//Initialize Player Components
moveController = GetComponent<CharacterController>(); // Character Controller
rB = GetComponent<Rigidbody>(); //Rigid Body
capCol = GetComponent<CapsuleCollider>(); // Capsule Collider
capCol.enabled = false;
//Wallrun
wallRun = gameObject.GetComponent<dWallRun>();
parentObj = transform.parent.gameObject;
animator = GetComponent<Animator>();
blink = gameObject.GetComponent<dBlink>();
//Initialize Scripts
pStats = GetComponent<PlayerStats>(); // PlayerStats
wallRun = GetComponent<dWallRun>(); //Wallrun
blink = GetComponent<dBlink>(); //Blink
up = this.gameObject.GetComponentInParent<Transform>().up;
//Get parents up direction
up = GetComponentInParent<Transform>().up;
//
//Coyote Timer Initialization
curCoyJumpTimer = coyJumpTimer;
}
void Start()
@@ -121,58 +136,34 @@ public class dPlayerMovement : NetworkBehaviour
// Otherwise we let the server handle moving us
//if (!IsLocalPlayer) { return; }
//Controls for camera
if(cam.enabled){
Rotation();
}
if(cam.enabled) Rotation();
else Debug.Log("Cam Disabled");
//Allow Movement when moveController is enabled
if(moveController.enabled == true){
//input controls for movement
InputController();
//if suffiecient impact magnitude is applied then move player
//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);
}
else{
if (RagdollTimer() == 0){
//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
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");
g -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,g,0));
}
//TEMP FOR TESTING RAGDOLL
//Right Click to ragdoll the player
// if (Input.GetMouseButton(1) && heldDown == false){
// getHit(new Vector3(vel.x, 0, vel.z), 30);
// heldDown = true;
// }
// if(!Input.GetMouseButton(1)){
// heldDown = false;
// }
if(pStats.HasBlink == true){
blink.BlinkMove();
}
//TEMP FOR TESTING
//Checks if player should respawn
//Respawn();
}
@@ -185,7 +176,6 @@ public class dPlayerMovement : NetworkBehaviour
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();
@@ -193,20 +183,34 @@ public class dPlayerMovement : NetworkBehaviour
//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
Gravity();
driftVel = Vector3.Lerp(driftVel, vel, pStats.Traction * Time.deltaTime);
//Moving outside basic wasd
//Jump Function
//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 < .510f)
{
if(animator != null) animator.SetBool("isRunning", false);
}
//Move Player
moveController.Move(driftVel);
moveController.Move(driftVel + (moveY * Time.deltaTime));
}
@@ -245,9 +249,9 @@ public class dPlayerMovement : NetworkBehaviour
//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;
@@ -259,82 +263,102 @@ public class dPlayerMovement : NetworkBehaviour
private void Jump()
{
//If space/south gamepad button is pressed apply an upwards force to the player
if (Input.GetAxis("Jump") != 0 && !jumpPressed && curJumpNum + 1 < pStats.JumpNum && !isSliding)
if (Input.GetAxis("Jump") != 0 && !jumpHeld && curJumpNum < pStats.JumpNum && !isSliding)
{
if(wallRun.IsWallRunning()){
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 1.3f);
AddImpact(transform.up, pStats.JumpPow);
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 20f);
g = pStats.JumpPow;
}
else{
AddImpact(transform.up, pStats.JumpPow);
g = pStats.JumpPow;
}
curJumpNum++;
jumpPressed = true;
jumpHeld = true;
}
//Last time Jumped
lastTimeJumped = Time.time;
//If grounded no jumps have been used
if(isGrounded){
curJumpNum = 0;
}
//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 space/south face gamepad button isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0) jumpPressed = false;
if (Input.GetAxis("Jump") == 0){
jumpHeld = false;
}
}
//PlayerScript
//Get and update PlayerValues for other scripts
//Get jumpHeld
public bool GetJumpPressed(){
return jumpPressed;
return jumpHeld;
}
//Get player cam
public Camera GetPlayerCamera()
{
return cam;
}
//Update Player Velocity
public void AddPlayerVelocity(Vector3 additiveVelocity)
{
vel += additiveVelocity;
}
//Set Player Velocity
public void SetPlayerVelocity(Vector3 newVelocity)
{
vel = newVelocity;
}
//Reduce player Jump
public void decrementCurrentJumpNumber()
{
curJumpNum--;
}
//Camera and Player Rotation
//Camera and player rotation
private void Rotation()
{
//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 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 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;
//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;
}
}
}
@@ -344,7 +368,7 @@ public class dPlayerMovement : NetworkBehaviour
//Respawns player if they fall below a certain point
private void Respawn()
{
if (transform.position.y < -1)
if (transform.position.y < -5)
{
transform.position = new Vector3(1f, 3f, 1f);
}
@@ -352,35 +376,71 @@ public class dPlayerMovement : NetworkBehaviour
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void Gravity(){
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void UpdateGravity(){
//Gliding
if(jumpPressed && pStats.HasGlider){
vel.y -= (pStats.PlayerGrav-18) * Time.deltaTime;
if(pStats.HasGlider && g < 0 && jumpHeld){
//Gravity with glider
GravityCalculation(10);
//Set temp values to put traction back to normal
if(tempSet == false){
tempTraction = pStats.Traction;
pStats.Traction = 1.0f;
tempSet = true;
}
}
else if(!jumpPressed && pStats.HasGlider){
//Wallrunning
else if (pStats.HasWallrun) {
//Run wall run script
wallRun.WallRunRoutine();
//if wallrunning apply different gravity
if(wallRun.IsWallRunning()){
GravityCalculation(4);
}
//Normal gravity if not wallrunning
else{
GravityCalculation(pStats.PlayerGrav);
}
}
else{
//if temporary values have been set restore them back to the normal values
if(tempSet == true){
pStats.Traction = tempTraction;
tempSet = false;
}
//Normal Gravity
vel.y -= pStats.PlayerGrav * Time.deltaTime;
//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;
}
//Wallrunning
else if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
//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){
g -= grav * Time.deltaTime;
}
//else don't apply gravity
else{
vel.y -= pStats.PlayerGrav * Time.deltaTime;
g = 0;
}
}
@@ -390,10 +450,12 @@ public class dPlayerMovement : NetworkBehaviour
{
// 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)) //&& 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
if (Physics.Raycast(groundRay, out groundHit, moveController.height + groundCheckDistance) && !jumpHeld ) //&& 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)
@@ -465,6 +527,7 @@ public class dPlayerMovement : NetworkBehaviour
pStats.Traction = 0.01f;
}
transform.Rotate(Vector3.forward * -sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
pStats.Traction += .004f;
}
else{
@@ -472,20 +535,40 @@ public class dPlayerMovement : NetworkBehaviour
}
//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 nothing is above the object, stop sliding
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);
this.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
isSliding = false;
moveController.height = 2.0f;
pStats.Traction = originalTraction;
}
else{
Debug.Log("Object above you");
}
}
}
public void CancelMomentum()
{
pStats.CurVel = 0;
vel = Vector3.zero;
moveX = Vector3.zero;
moveZ = Vector3.zero;
moveController.enabled = false;
}
private IEnumerator RespawnTimer()
{
float duration = 2f;
float normalizedTime = 0;
while (normalizedTime <= 1f)
{
normalizedTime += Time.deltaTime / duration;
yield return null;
}
moveController.enabled = true;
}
}

View File

@@ -12,12 +12,12 @@ public class KickController : NetworkBehaviour
//slightly bad practice, when merging find a better work around
private bool isDiveKicking = false;
private CharacterController characterController;
public PlayerMovement pMove;
public PlayerStats pStats;
void Start(){
pStats = GetComponent<PlayerStats>();
pMove = GetComponent<PlayerMovement>();
characterController = this.gameObject.GetComponent<CharacterController>();
leg = transform.GetChild(0).gameObject;
leg.SetActive(false);
@@ -31,7 +31,7 @@ public class KickController : NetworkBehaviour
//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 && characterController.isGrounded == false)
if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false && pMove.isGrounded == false)
{
Debug.Log("dive");
// if kicking in air, kick until grounded (maybe add some foward momentum if needeD)
@@ -40,13 +40,13 @@ public class KickController : NetworkBehaviour
leg.SetActive(true);
}
//otherwise do ground kick for .3 seconds
else if (( Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false){
Debug.Log("kick");
else if ((Input.GetKeyDown(KeyCode.F) || Input.GetAxis("Kick") != 0) && isKicking == false){
StartCoroutine(Kicking(.3f));
}
//once dive kick touches ground, set back to normal state
if(characterController.isGrounded == true && isDiveKicking == true){
if (pMove.isGrounded == true && isDiveKicking == true)
{
isDiveKicking = false;
isKicking = false;
leg.SetActive(false);
@@ -63,7 +63,7 @@ public class KickController : NetworkBehaviour
}
private void OnCollisionEnter(Collision collision)
private void OnCollisionEnter(Collision collision)
{
//if (!IsLocalPlayer) { return; }
Collider myCollider = collision.contacts[0].thisCollider;
@@ -75,6 +75,9 @@ public class KickController : NetworkBehaviour
Debug.Log(direction);
collision.rigidbody.AddForce(direction * pStats.KickPow, ForceMode.Impulse);
}
if (collision.transform.CompareTag("destroyable") && myCollider == leg.GetComponent<Collider>()){
collision.transform.gameObject.GetComponent<BreakableBlock>().damage(pStats.KickPow);
}
}
}

View File

@@ -32,7 +32,7 @@ public class GrapplingHook : NetworkBehaviour
// Update is called once per frame
void Update()
{
//if (!IsLocalPlayer) { return; }
if (!IsLocalPlayer) { return; }
if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit
{

View File

@@ -112,13 +112,11 @@ public class WallRun : NetworkBehaviour
{
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * playerMovementController.pStats.PlayerGrav * Time.deltaTime));
}
}

View File

@@ -19,7 +19,7 @@ MonoBehaviour:
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: 100
jumpPowM: 10
jumpNumM: 0
tractionM: 0
kickPowM: 0

View File

@@ -19,7 +19,7 @@ MonoBehaviour:
minVelM: 0
curVelM: 0
accM: 0
jumpPowM: -50
jumpPowM: -5
jumpNumM: 1
tractionM: 0
kickPowM: 0

View File

@@ -18,6 +18,7 @@ public class PlayerMovement : NetworkBehaviour
private Vector3 moveZ;
private Vector3 moveX;
private Vector3 driftVel;
private Vector3 lerpY;
//Player prefab
private GameObject parentObj;
@@ -26,16 +27,24 @@ public class PlayerMovement : NetworkBehaviour
private CharacterController moveController;
//Jump value
public int curJumpNum;
private bool jumpPressed;
public int curJumpNum; // current Jumps used
private bool jumpHeld; // Is jump being held
float coyJumpTimer = 0.2f; // Default Coyote Jump time
float curCoyJumpTimer; // current Coyote Jump time
public float lowJumpMultiplier; // Short jump multiplier
public float fallMultiplier; // High Jump Multiplier
private float g = 0; // the y velocity
//Glide Values
bool tempSet = false;
float tempTraction = 0.0f;
//Jump physics
//Impact physics
private float mass = 5.0F; // defines the character mass
private Vector3 impact = Vector3.zero;
private float distToGround;
//Wallrunning
private WallRun wallRun;
@@ -49,7 +58,6 @@ public class PlayerMovement : NetworkBehaviour
private RaycastHit groundHit;
//Camera Variables
private LayerMask ignoreP;
private Vector3 camRotation;
public Camera cam;
@@ -78,25 +86,36 @@ public class PlayerMovement : NetworkBehaviour
private Vector3 up;
private bool qDown;
//Kick Variables
//Blink
private Blink blink;
//Animation controller
Animator animator;
void Awake()
{
//Initialize Components
moveController = GetComponent<CharacterController>();
rB = GetComponent<Rigidbody>();
capCol = GetComponent<CapsuleCollider>();
pStats = GetComponent<PlayerStats>();
parentObj = transform.parent.gameObject;
//Initialize Player Components
moveController = GetComponent<CharacterController>(); // Character Controller
rB = GetComponent<Rigidbody>(); //Rigid Body
capCol = GetComponent<CapsuleCollider>(); // Capsule Collider
capCol.enabled = false;
//Wallrun
wallRun = gameObject.GetComponent<WallRun>();
up = this.gameObject.GetComponentInParent<Transform>().up;
parentObj = transform.parent.gameObject;
animator = GetComponent<Animator>();
//Initialize Scripts
pStats = GetComponent<PlayerStats>(); // PlayerStats
wallRun = GetComponent<WallRun>(); //Wallrun
blink = GetComponent<Blink>(); //Blink
//Get parents up direction
up = GetComponentInParent<Transform>().up;
//Coyote Timer Initialization
curCoyJumpTimer = coyJumpTimer;
}
void Start()
{
distToGround = GetComponent<Collider>().bounds.extents.y;
@@ -111,6 +130,8 @@ public class PlayerMovement : NetworkBehaviour
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void FixedUpdate()
{
@@ -118,46 +139,42 @@ public class PlayerMovement : NetworkBehaviour
// Otherwise we let the server handle moving us
if (!IsLocalPlayer) { return; }
//Controls for camera
if(cam.enabled){
Rotation();
}
if(cam.enabled) Rotation();
else Debug.Log("Cam Disabled");
//Allow Movement when moveController is enabled
if(moveController.enabled == true){
//input controls for movement
InputController();
//if suffiecient impact magnitude is applied then move player
//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);
}
else{
if (RagdollTimer() == 0){
//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
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");
g -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,g,0));
}
//TEMP FOR TESTING
//Checks if player should respawn
Respawn();
//Respawn();
}
//Reads inputs and moves player
private void InputController()
{
@@ -165,7 +182,6 @@ public class PlayerMovement : NetworkBehaviour
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();
@@ -173,23 +189,37 @@ public class PlayerMovement : NetworkBehaviour
//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
Gravity();
//Adds persisting momentum to player
driftVel = Vector3.Lerp(driftVel, vel, pStats.Traction * Time.deltaTime);
//Moving outside basic wasd
//Jump Function
//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 < .510f)
{
if(animator != null) animator.SetBool("isRunning", false);
}
//Move Player
moveController.Move(driftVel);
moveController.Move(driftVel + (moveY * Time.deltaTime));
}
//Calculates speed current player needs to be going
public float PlayerSpeed()
{
@@ -199,18 +229,21 @@ public class PlayerMovement : NetworkBehaviour
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
{
@@ -226,6 +259,7 @@ public class PlayerMovement : NetworkBehaviour
{
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;
@@ -236,73 +270,86 @@ public class PlayerMovement : NetworkBehaviour
//Jump Function
private void Jump()
{
//If space is pressed apply an upwards force to the player
if ((Input.GetAxis("Jump") != 0) && !jumpPressed && curJumpNum + 1 < pStats.JumpNum && !isSliding)
//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 * 1.3f);
AddImpact(transform.up, pStats.JumpPow);
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 20f);
g = pStats.JumpPow;
}
else{
AddImpact(transform.up, pStats.JumpPow);
g = pStats.JumpPow;
}
curJumpNum++;
jumpPressed = true;
jumpHeld = true;
}
//Last time Jumped
lastTimeJumped = Time.time;
//If grounded no jumps have been used
//If grounded no jumps have been used and coyote Timer is refreshed
if(isGrounded){
curJumpNum = 0;
}
curCoyJumpTimer = coyJumpTimer;
curJumpNum = 0;
}
//else start the coyote timer
else curCoyJumpTimer -= Time.deltaTime;
//If space isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0) jumpPressed = false;
//if jump is being held coyote timer is zero
if(jumpHeld) curCoyJumpTimer = 0;
//If space/south face gamepad button isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0){
jumpHeld = false;
}
}
//PlayerScript
//Get and update PlayerValues for other scripts
//Get jumpHeld
public bool GetJumpPressed(){
return jumpPressed;
return jumpHeld;
}
//Get player cam
public Camera GetPlayerCamera()
{
return cam;
}
//Update Player Velocity
public void AddPlayerVelocity(Vector3 additiveVelocity)
{
vel += additiveVelocity;
}
//Set Player Velocity
public void SetPlayerVelocity(Vector3 newVelocity)
{
vel = newVelocity;
}
//Camera and Player Rotation
//Reduce player Jump
public void decrementCurrentJumpNumber()
{
curJumpNum--;
}
//Camera
//Camera and player rotation
private void Rotation()
{
Vector3 lastCamPos = new Vector3(0,0,0);
Vector3 rotOffset = transform.localEulerAngles;
//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"));
@@ -315,6 +362,7 @@ public class PlayerMovement : NetworkBehaviour
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;
@@ -330,7 +378,7 @@ public class PlayerMovement : NetworkBehaviour
//Respawns player if they fall below a certain point
private void Respawn()
{
if (transform.position.y < -1)
if (transform.position.y < -5)
{
transform.position = new Vector3(1f, 3f, 1f);
}
@@ -338,35 +386,71 @@ public class PlayerMovement : NetworkBehaviour
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void Gravity(){
//Gravity Function for adjusting y-vel due to wallrun/glide/etc
private void UpdateGravity(){
//Gliding
if(jumpPressed && pStats.HasGlider){
vel.y -= (pStats.PlayerGrav-18) * Time.deltaTime;
if(pStats.HasGlider && g < 0 && jumpHeld){
//Gravity with glider
GravityCalculation(10);
//Set temp values to put traction back to normal
if(tempSet == false){
tempTraction = pStats.Traction;
pStats.Traction = 1.0f;
tempSet = true;
}
}
else if(!jumpPressed && pStats.HasGlider){
//Wallrunning
else if (pStats.HasWallrun) {
//Run wall run script
wallRun.WallRunRoutine();
//if wallrunning apply different gravity
if(wallRun.IsWallRunning()){
GravityCalculation(4);
}
//Normal gravity if not wallrunning
else{
GravityCalculation(pStats.PlayerGrav);
}
}
else{
//if temporary values have been set restore them back to the normal values
if(tempSet == true){
pStats.Traction = tempTraction;
tempSet = false;
}
//Normal Gravity
vel.y -= pStats.PlayerGrav * Time.deltaTime;
//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;
}
//Wallrunning
else if (pStats.HasWallrun) { wallRun.WallRunRoutine(); } //adjusted later if we are wallrunning
//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){
g -= grav * Time.deltaTime;
}
//else don't apply gravity
else{
vel.y -= pStats.PlayerGrav * Time.deltaTime;
g = 0;
}
}
@@ -376,10 +460,12 @@ public class PlayerMovement : NetworkBehaviour
{
// 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)) //&& 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
if (Physics.Raycast(groundRay, out groundHit, moveController.height + groundCheckDistance) && !jumpHeld ) //&& 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)
@@ -440,7 +526,8 @@ public class PlayerMovement : NetworkBehaviour
//Slide Function
private void Slide(){
if (Input.GetKey(KeyCode.JoystickButton1) || Input.GetKey(KeyCode.Q)){
//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;
@@ -450,6 +537,7 @@ public class PlayerMovement : NetworkBehaviour
pStats.Traction = 0.01f;
}
transform.Rotate(Vector3.forward * -sensitivity * Time.deltaTime * Input.GetAxis("Mouse X"));
pStats.Traction += .004f;
}
else{
@@ -457,18 +545,17 @@ public class PlayerMovement : NetworkBehaviour
}
//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 nothing is above the object, stop sliding
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);
this.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0);
isSliding = false;
moveController.height = 2.0f;
pStats.Traction = originalTraction;
}
else{
Debug.Log("Object above you");
}
}
}

View File

@@ -6,14 +6,14 @@ using UnityEngine.Assertions;
public class PlayerStats : MonoBehaviour
{
//Maximum possible player speed
[SerializeField] private float maxVel = 25.0f;
[SerializeField] private float maxVel = 30.0f;
public float MaxVel{
get{ return maxVel; }
set{ maxVel = value; }
}
//Minimum possible player speed
[SerializeField] private float minVel = 2.0f;
[SerializeField] private float minVel = 5.0f;
public float MinVel{
get{ return minVel; }
set{ minVel = value; }
@@ -34,7 +34,7 @@ public class PlayerStats : MonoBehaviour
}
//Player Jump power
[SerializeField] private float jumpPow = 300.0f;
[SerializeField] private float jumpPow = 63.0f;
public float JumpPow{
get{ return jumpPow; }
set{ jumpPow = value; }
@@ -69,7 +69,7 @@ public class PlayerStats : MonoBehaviour
}
//Gravity Affecting the player
[SerializeField] private float playerGrav = 20.0f;
[SerializeField] private float playerGrav = 200.0f;
public float PlayerGrav{
get{ return playerGrav; }
set{ playerGrav = value; }

View File

@@ -10,11 +10,62 @@ public class PostGameUI : NetworkBehaviour {
[SerializeField] private TMP_Text ReturnToLobbyText;
[SerializeField] private int ReturnToLobbyTimer;
[SerializeField] private TMP_Text HeaderText;
private string TEXT;
void Start() {
ReturnToLobbyText.text = "Returning to the lobby in " + ReturnToLobbyTimer + " seconds...";
StartCoroutine(BeginCountdown());
//todo: do logic to determine and update who won the round
UpdateWinnerTextServerRPC();
}
void Update() {
HeaderText.text = TEXT;
}
[ServerRpc]
private void UpdateWinnerTextServerRPC() {
List<string> playerFinishedNames = new List<string>();
string kingName = "";
int winnerCount = 0;
string winText = "";
foreach (PlayerData pData in ServerGameNetPortal.Instance.clientData.Values) {
if (pData.IsKing) {
kingName = pData.PlayerName;
} else {
if (pData.Finished)
{
playerFinishedNames.Add(pData.PlayerName);
winnerCount++;
}
}
}
if (winnerCount > 0) {
// Runners win
switch (winnerCount) {
case 1:
winText = "And the winner is the Runner " + playerFinishedNames[0] + "!";
break;
case 2:
winText = "And the winners are the Runners " + playerFinishedNames[0] + " and " + playerFinishedNames[1] + "!";
break;
}
} else {
// King wins
winText = "And the winner is King " + kingName + "!";
}
UpdateWinnerTextClientRPC(winText);
}
[ClientRpc]
private void UpdateWinnerTextClientRPC(string winnerText) {
TEXT = winnerText;
}
IEnumerator BeginCountdown() {