Im making a grappling gun, that pulls an object towards the player if the layer is LightWeight
, and pull the player towards the object if the layer is Ground
int groundLayer_mask = LayerMask.GetMask("Ground");
int lightWeightLayer_mask = LayerMask.GetMask("LightWeight");
//Shoots a raycast, and only works if layer is Ground
if (Physics.Raycast(Shoulder.transform.position, cam.transform.forward, out raycastHit, float.PositiveInfinity, groundLayer_mask))
{
//Hit Something
debugHitpointTransform.position = raycastHit.point;
hookshotPosition = raycastHit.point;
hookShotSize = 0f;
HookShotTransform.gameObject.SetActive(true);
HookShotTransform.localScale = Vector3.zero;
layerHit = 0;
state = State.HookShotThrown;
}
//Shoots a raycast, and only works if layer is LightWeight
else if (Physics.Raycast(Shoulder.transform.position, cam.transform.forward, out raycastHit, float.PositiveInfinity, lightWeightLayer_mask))
{
//Hit Something
debugHitpointTransform.position = raycastHit.point;
hookshotPosition = raycastHit.point;
hookShotSize = 0f;
HookShotTransform.gameObject.SetActive(true);
HookShotTransform.localScale = Vector3.zero;
layerHit = 1;
state = State.HookShotThrown;
}
But if im looking in the direction of an object with Ground
layer, even if there is one with the layer LightWeight
closer than the one with Ground
, it goes for the one with Ground
cuz i have it's if statement first. Any way to make it either not go through the object infront just cuz the first if is looking for one behind, or to make it prioritize the one infront?