mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-23 19:04:32 -05:00
Started Implementing Grappling Hook
-Created script to handle grappling hook with structure of intended code outlined -Added tags for grappling points
This commit is contained in:
67
Assets/Scripts/PlayerScripts/GrapplingHook.cs
Normal file
67
Assets/Scripts/PlayerScripts/GrapplingHook.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GrapplingHook : MonoBehaviour
|
||||
{
|
||||
public float maxGrappleDistance = 25;
|
||||
|
||||
private bool isGrappled;
|
||||
private int hookPointIndex;
|
||||
private GameObject hookPoint;
|
||||
private GameObject[] hookPoints;
|
||||
private float distance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
isGrappled = false;
|
||||
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E)) //If grapple button is hit
|
||||
{
|
||||
if (!isGrappled) //If we are not grappling
|
||||
{
|
||||
hookPointIndex = FindHookPoint(); //Find the nearest hook point within max distance
|
||||
if (hookPointIndex != -1) //If there is a hookpoint
|
||||
{
|
||||
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
|
||||
//physics set up?
|
||||
isGrappled = true; //toggle grappling state
|
||||
}
|
||||
}
|
||||
else //Else we are grappling
|
||||
{
|
||||
//physics tear down?
|
||||
isGrappled = false; //toggle grappling state to release
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (isGrappled)
|
||||
{
|
||||
//Do grappling physics based on hookPoint
|
||||
}
|
||||
}
|
||||
|
||||
int FindHookPoint()
|
||||
{
|
||||
float least = maxGrappleDistance;
|
||||
int index = -1;
|
||||
for(int i = 0; i<hookPoints.Length; i++)
|
||||
{
|
||||
distance = Vector3.Distance(gameObject.transform.position, hookPoints[i].transform.position);
|
||||
if (distance <= least)
|
||||
{
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerScripts/GrapplingHook.cs.meta
Normal file
11
Assets/Scripts/PlayerScripts/GrapplingHook.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cee70ea30de57ec43a325c1ca6257526
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user