grapple still doesn't work fixed some other values with prefabs

This commit is contained in:
Melbyj1125
2021-12-10 22:36:40 -06:00
parent 610d8b832e
commit 946e2146a3
8 changed files with 269 additions and 67 deletions

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