Merge branch 'MelbyFinalSprint'

This commit is contained in:
Melbyj1125
2021-12-10 23:17:37 -06:00
10 changed files with 282 additions and 69 deletions

View File

@@ -5,7 +5,7 @@ using UnityEngine;
public class dGrapplingHook : NetworkBehaviour
{
public float maxGrappleDistance = 25;
public float maxGrappleDistance = 25;
public bool isGrappled;
private int hookPointIndex;
@@ -16,14 +16,13 @@ public class dGrapplingHook : NetworkBehaviour
private CharacterController movementController;
private dPlayerMovement playerMovement;
private PlayerStats pStats;
private Vector3 hookLerp;
public float ropeLength;
[SerializeField] private float ropeLength;
private float climbRate = 5;
// Start is called before the first frame update
void Start()
{
isGrappled = false;
isGrappled = false;
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
movementController = gameObject.GetComponent<CharacterController>();
playerMovement = gameObject.GetComponent<dPlayerMovement>();
@@ -35,7 +34,6 @@ public class dGrapplingHook : NetworkBehaviour
{
//if (!IsLocalPlayer) { return; }
//if E or left face gamepad button is pressed is slightly pressed
if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit
{
if (!isGrappled) //If we are not grappling
@@ -47,7 +45,7 @@ public class dGrapplingHook : NetworkBehaviour
ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f;
isGrappled = true; //toggle grappling state
}
}
}
else //Else we are grappling
{
//physics tear down?
@@ -62,7 +60,6 @@ public class dGrapplingHook : NetworkBehaviour
{
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
//if left shift or left bumper held down
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.JoystickButton4)) //Extend hook
{
ropeLength += climbRate * Time.deltaTime;
@@ -82,24 +79,23 @@ public class dGrapplingHook : NetworkBehaviour
//Debug.Log(ropeLength.ToString());
}
//Do grappling physics based on hookPoint
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength)
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength )
{
movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * Time.deltaTime);
//Character controller move?
//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
//Impact Based
Debug.Log("y");
playerMovement.g = 2;
movementController.Move((hookPoint.transform.position - gameObject.transform.position) * Time.deltaTime);
}
}
if(playerMovement.GetJumpPressed()){
isGrappled = false;
}
if(playerMovement.GetJumpPressed()) isGrappled = false;
}
int FindHookPoint()
{
float least = maxGrappleDistance;
int index = -1;
for (int i = 0; i < hookPoints.Length; i++)
for(int i = 0; i<hookPoints.Length; i++)
{
distance = Vector3.Distance(gameObject.transform.position, hookPoints[i].transform.position);
if (distance <= least)
@@ -109,4 +105,60 @@ public class dGrapplingHook : NetworkBehaviour
}
return index;
}
///////////Hookshot Concept
// public float maxGrappleDistance = 25;
// public bool isGrappled;
// private Vector3 hookPoint;
// private float distance;
// public float propelPower = 100;
// private CharacterController movementController;
// private dPlayerMovement playerMovement;
// private PlayerStats pStats;
// private Camera cam;
// private Vector3 forwardHookLerp;
// private Vector3 upwardsHookLerp;
// // Start is called before the first frame update
// void Start()
// {
// isGrappled = false;
// movementController = gameObject.GetComponent<CharacterController>();
// playerMovement = gameObject.GetComponent<dPlayerMovement>();
// pStats = gameObject.GetComponent<PlayerStats>();
// cam = playerMovement.cam;
// }
// private void FixedUpdate()
// {
// getGrapplePoint();
// //Debug.Log((hookPoint.transform.position - transform.position).normalized);
// if (isGrappled && !Input.GetKeyDown(KeyCode.E))
// {
// //playerMovement.AddImpact((hookPoint - transform.position), propelPower);
// forwardHookLerp = Vector3.Lerp(forwardHookLerp, transform.forward * 50, .03f);
// movementController.Move(forwardHookLerp * Time.deltaTime);
// upwardsHookLerp = Vector3.Lerp(upwardsHookLerp, (hookPoint - transform.position).normalized * Vector3.Distance(transform.position, hookPoint) * propelPower, .03f);
// movementController.Move(upwardsHookLerp * Time.deltaTime);
// isGrappled = false;
// }
// }
// private void getGrapplePoint(){
// //if E or left face gamepad button is pressed is slightly pressed
// if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit
// {
// if (!isGrappled) //If we are not grappling
// {
// if(Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit raycastHit)){
// if(raycastHit.collider.gameObject.transform.tag == "HookPoint"){
// isGrappled = true;
// hookPoint = new Vector3 (raycastHit.point.x,raycastHit.point.y,raycastHit.point.z);
// }
// }
// }
// }
// }
}

View File

@@ -32,7 +32,7 @@ public class dPlayerMovement : NetworkBehaviour
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
public float g = 0; // the y velocity
//Glide Values
bool tempSet = false;
@@ -99,7 +99,7 @@ public class dPlayerMovement : NetworkBehaviour
moveController = GetComponent<CharacterController>(); // Character Controller
rB = GetComponent<Rigidbody>(); //Rigid Body
capCol = GetComponent<CapsuleCollider>(); // Capsule Collider
capCol.enabled = false;
capCol.enabled = true;
parentObj = transform.parent.gameObject;
animator = GetComponent<Animator>();
@@ -296,6 +296,8 @@ public class dPlayerMovement : NetworkBehaviour
//if jump is being held coyote timer is zero
if(jumpHeld) curCoyJumpTimer = 0;
if(grapple.isGrappled && curJumpNum == 2) curJumpNum = 1;
//If space/south face gamepad button isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0){
jumpHeld = false;
@@ -438,10 +440,9 @@ public class dPlayerMovement : NetworkBehaviour
}
//apply gravity if not grounded and coyote timer is less than 0
if((isGrounded == false && curCoyJumpTimer <= 0) || (!grapple.isGrappled && isGrounded == false)){
if(isGrounded == false && curCoyJumpTimer <= 0){
g -= grav * Time.deltaTime;
}
//else don't apply gravity
else{
g = 0;

View File

@@ -5,9 +5,9 @@ using UnityEngine;
public class GrapplingHook : NetworkBehaviour
{
public float maxGrappleDistance = 25;
public float maxGrappleDistance = 25;
private bool isGrappled;
public bool isGrappled;
private int hookPointIndex;
private GameObject hookPoint;
private GameObject[] hookPoints;
@@ -16,7 +16,7 @@ public class GrapplingHook : NetworkBehaviour
private CharacterController movementController;
private PlayerMovement playerMovement;
private PlayerStats pStats;
private float ropeLength;
[SerializeField] private float ropeLength;
private float climbRate = 5;
// Start is called before the first frame update
@@ -56,6 +56,7 @@ public class GrapplingHook : NetworkBehaviour
private void FixedUpdate()
{
if (!IsLocalPlayer) { return; }
if (isGrappled)
{
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
@@ -79,15 +80,16 @@ public class GrapplingHook : NetworkBehaviour
//Debug.Log(ropeLength.ToString());
}
//Do grappling physics based on hookPoint
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength)
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
Debug.Log("y");
playerMovement.g = 2;
movementController.Move((hookPoint.transform.position - gameObject.transform.position) * Time.deltaTime);
}
}
if(playerMovement.GetJumpPressed()) isGrappled = false;
}
int FindHookPoint()
@@ -104,4 +106,60 @@ public class GrapplingHook : NetworkBehaviour
}
return index;
}
///////////Hookshot Concept
// public float maxGrappleDistance = 25;
// public bool isGrappled;
// private Vector3 hookPoint;
// private float distance;
// public float propelPower = 100;
// private CharacterController movementController;
// private dPlayerMovement playerMovement;
// private PlayerStats pStats;
// private Camera cam;
// private Vector3 forwardHookLerp;
// private Vector3 upwardsHookLerp;
// // Start is called before the first frame update
// void Start()
// {
// isGrappled = false;
// movementController = gameObject.GetComponent<CharacterController>();
// playerMovement = gameObject.GetComponent<dPlayerMovement>();
// pStats = gameObject.GetComponent<PlayerStats>();
// cam = playerMovement.cam;
// }
// private void FixedUpdate()
// {
// getGrapplePoint();
// //Debug.Log((hookPoint.transform.position - transform.position).normalized);
// if (isGrappled && !Input.GetKeyDown(KeyCode.E))
// {
// //playerMovement.AddImpact((hookPoint - transform.position), propelPower);
// forwardHookLerp = Vector3.Lerp(forwardHookLerp, transform.forward * 50, .03f);
// movementController.Move(forwardHookLerp * Time.deltaTime);
// upwardsHookLerp = Vector3.Lerp(upwardsHookLerp, (hookPoint - transform.position).normalized * Vector3.Distance(transform.position, hookPoint) * propelPower, .03f);
// movementController.Move(upwardsHookLerp * Time.deltaTime);
// isGrappled = false;
// }
// }
// private void getGrapplePoint(){
// //if E or left face gamepad button is pressed is slightly pressed
// if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) //If grapple button is hit
// {
// if (!isGrappled) //If we are not grappling
// {
// if(Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit raycastHit)){
// if(raycastHit.collider.gameObject.transform.tag == "HookPoint"){
// isGrappled = true;
// hookPoint = new Vector3 (raycastHit.point.x,raycastHit.point.y,raycastHit.point.z);
// }
// }
// }
// }
// }
}

View File

@@ -6,7 +6,6 @@ using UnityEngine.UI;
public class PlayerMovement : NetworkBehaviour
{
//Controller object
//Scripts
public PlayerStats pStats;
@@ -17,8 +16,7 @@ public class PlayerMovement : NetworkBehaviour
private Vector3 moveZ;
private Vector3 moveX;
private Vector3 driftVel;
private Vector3 lerpY;
public Vector3 driftVel;
//Player prefab
private GameObject parentObj;
@@ -29,11 +27,11 @@ public class PlayerMovement : NetworkBehaviour
//Jump value
public int curJumpNum; // current Jumps used
private bool jumpHeld; // Is jump being held
float coyJumpTimer = 0.2f; // Default Coyote Jump time
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
public float g = 0; // the y velocity
//Glide Values
bool tempSet = false;
@@ -44,7 +42,6 @@ public class PlayerMovement : NetworkBehaviour
private Vector3 impact = Vector3.zero;
private float distToGround;
//Wallrunning
private WallRun wallRun;
@@ -73,14 +70,14 @@ public class PlayerMovement : NetworkBehaviour
private Rigidbody rB;
private CapsuleCollider capCol;
private bool firstHit = false;
//private bool heldDown = false; //Variable for testing ragdoll reenable if needed
//private bool heldDown = false; //Variable for testing Ragdoll reenable if needed
private bool beginRagTimer = false;
private float ragTime;
private Vector3 prevRot;
private Vector3 hitForce;
//Slide Variables
private bool isSliding = false;
public bool isSliding = false;
private float originalTraction;
private RaycastHit ray;
private Vector3 up;
@@ -89,6 +86,9 @@ public class PlayerMovement : NetworkBehaviour
//Blink
private Blink blink;
private GrapplingHook grapple;
//Animation controller
Animator animator;
@@ -98,7 +98,7 @@ public class PlayerMovement : NetworkBehaviour
moveController = GetComponent<CharacterController>(); // Character Controller
rB = GetComponent<Rigidbody>(); //Rigid Body
capCol = GetComponent<CapsuleCollider>(); // Capsule Collider
capCol.enabled = false;
capCol.enabled = true;
parentObj = transform.parent.gameObject;
animator = GetComponent<Animator>();
@@ -106,22 +106,22 @@ public class PlayerMovement : NetworkBehaviour
pStats = GetComponent<PlayerStats>(); // PlayerStats
wallRun = GetComponent<WallRun>(); //Wallrun
blink = GetComponent<Blink>(); //Blink
grapple = GetComponent<GrapplingHook>();
//Get parents up direction
up = GetComponentInParent<Transform>().up;
//
//Coyote Timer Initialization
curCoyJumpTimer = coyJumpTimer;
}
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
@@ -130,8 +130,6 @@ public class PlayerMovement : NetworkBehaviour
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void FixedUpdate()
{
@@ -167,10 +165,8 @@ public class PlayerMovement : NetworkBehaviour
g -= pStats.PlayerGrav * Time.deltaTime;
rB.AddForce(new Vector3(0,g,0));
}
//TEMP FOR TESTING
//Checks if player should respawn
//Respawn();
Respawn();
}
@@ -200,6 +196,7 @@ public class PlayerMovement : NetworkBehaviour
//Slide Function
Slide();
//move animation
//if vel from input is greater than 0, start sprinting animation
if (PlayerSpeed() > 0.1)
@@ -209,8 +206,9 @@ public class PlayerMovement : NetworkBehaviour
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)
else if (driftVel.magnitude < .05f)
{
driftVel = Vector3.zero;
if(animator != null) animator.SetBool("isRunning", false);
}
@@ -229,21 +227,18 @@ 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
{
@@ -257,7 +252,7 @@ public class PlayerMovement : NetworkBehaviour
//Apply Impact for when force needs to be applied without ragdolling
public void AddImpact(Vector3 dir, float force)
{
if (!IsLocalPlayer) { return; }
//if (!IsLocalPlayer) { return; }
//Normalize direction multiply by force and add it to the impact
dir.Normalize();
@@ -274,7 +269,7 @@ public class PlayerMovement : NetworkBehaviour
if (Input.GetAxis("Jump") != 0 && !jumpHeld && curJumpNum < pStats.JumpNum && !isSliding)
{
if(wallRun.IsWallRunning()){
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 20f);
AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 10f);
g = pStats.JumpPow;
}
@@ -290,7 +285,7 @@ public class PlayerMovement : NetworkBehaviour
lastTimeJumped = Time.time;
//If grounded no jumps have been used and coyote Timer is refreshed
if(isGrounded){
if(isGrounded && g == 0){
curCoyJumpTimer = coyJumpTimer;
curJumpNum = 0;
}
@@ -300,14 +295,14 @@ public class PlayerMovement : NetworkBehaviour
//if jump is being held coyote timer is zero
if(jumpHeld) curCoyJumpTimer = 0;
if(grapple.isGrappled && curJumpNum == 2) curJumpNum = 1;
//If space/south face gamepad button isn't being pressed then jump is false
if (Input.GetAxis("Jump") == 0){
jumpHeld = false;
}
}
//Get and update PlayerValues for other scripts
//Get jumpHeld
public bool GetJumpPressed(){
@@ -380,7 +375,7 @@ public class PlayerMovement : NetworkBehaviour
{
if (transform.position.y < -5)
{
transform.position = new Vector3(1f, 3f, 1f);
TeleportPlayer(new Vector3(0,100,0));
}
}
@@ -435,22 +430,21 @@ public class PlayerMovement : NetworkBehaviour
private void GravityCalculation(float grav){
//apply slight upwards force for jump smoothing when g < 0
if(g < 0){
g += grav * (fallMultiplier - 1) * Time.deltaTime;
g += grav * (fallMultiplier - 1) * Time.deltaTime;
}
//apply smaller upwards force if jump is released early when jumping creating a short jump
else if (g > 0 && !Input.GetButton("Jump")){
g += grav * (lowJumpMultiplier - 1) * Time.deltaTime;
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;
if(isGrounded == false && curCoyJumpTimer <= 0){
g -= grav * Time.deltaTime;
}
//else don't apply gravity
else{
g = 0;
g = 0;
}
}
@@ -472,7 +466,7 @@ public class PlayerMovement : NetworkBehaviour
{
isGrounded = true;
// handle snapping to the ground
if (groundHit.distance > moveController.skinWidth)
if (groundHit.distance > moveController.skinWidth && !grapple.isGrappled)
{
moveController.Move(Vector3.down * groundHit.distance);
}
@@ -504,6 +498,7 @@ public class PlayerMovement : NetworkBehaviour
rB.isKinematic = true;
rB.detectCollisions = false;
transform.localEulerAngles = prevRot;
CancelMomentum();
}
//When to begin the ragdoll timer
@@ -590,7 +585,7 @@ public class PlayerMovement : NetworkBehaviour
vel = Vector3.zero;
moveX = Vector3.zero;
moveZ = Vector3.zero;
moveController.enabled = false;
driftVel = Vector3.zero;
}
private IEnumerator RespawnTimer()