look priority when grappling

This commit is contained in:
Melbyj1125
2022-04-06 13:42:28 -05:00
parent 510c41e062
commit 26fbdba535
3 changed files with 39 additions and 3 deletions

View File

@@ -27,6 +27,7 @@ public class dAerialStateManager : NetworkBehaviour
////Objects Sections
GameObject parentObj; // Parent object
public Camera cam;
////
////Components Section
@@ -479,17 +480,31 @@ public class dAerialStateManager : NetworkBehaviour
return false;
}
//Modify This So it Actually gets the nearest hook with a preference for the one they are looking at
//Finds the nearest hook to the player
int FindHookPoint()
{
float least = maxGrabDistance;
int index = -1;
bool inSightLine;
bool hookInSight = false;
for(int i = 0; i<hookPoints.Length; i++)
{
distance = Vector3.Distance(gameObject.transform.position, hookPoints[i].transform.position);
Vector3 screenPoint = cam.WorldToViewportPoint(hookPoints[i].transform.position);
inSightLine = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
if (distance <= least)
{
index = i;
if(inSightLine){
index = i;
least = distance;
hookInSight = true;
}
else if(!hookInSight && !inSightLine){
index = i;
}
}
}
return index;