This commit is contained in:
wheatv3015
2021-11-29 12:05:38 -06:00
parent e913df282f
commit 49dea1fcde
7 changed files with 1216 additions and 105 deletions

View File

@@ -13,18 +13,27 @@ public class dGrapplingHook : NetworkBehaviour
private GameObject[] hookPoints;
private float distance;
private CharacterController movementController;
private dPlayerMovement playerMovement;
private PlayerStats pStats;
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>();
pStats = gameObject.GetComponent<PlayerStats>();
}
// Update is called once per frame
void Update()
{
//if (!IsLocalPlayer) { return; }
if (Input.GetKeyDown(KeyCode.E)) //If grapple button is hit
{
if (!isGrappled) //If we are not grappling
@@ -33,10 +42,10 @@ public class dGrapplingHook : NetworkBehaviour
if (hookPointIndex != -1) //If there is a hookpoint
{
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
//physics set up?
ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f;
isGrappled = true; //toggle grappling state
}
}
}
else //Else we are grappling
{
//physics tear down?
@@ -49,7 +58,35 @@ public class dGrapplingHook : NetworkBehaviour
{
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
}
}
}
@@ -57,7 +94,7 @@ public class dGrapplingHook : NetworkBehaviour
{
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)

View File

@@ -172,7 +172,7 @@ public class dPlayerMovement : NetworkBehaviour
//TEMP FOR TESTING
//Checks if player should respawn
Respawn();
//Respawn();
}