I have a three Gameobject(striker)in unity lets say Red,Green and Blue.
when i apply gravity force to Green object i want to check if it is passed between Red and Blue or not? and i apply force to Red object i want to check also if it is passed between Green and Blue
Is there any line collider or somthing like that in unity?
Below i also attached a image for what i am trying to achieve
Create three layers for masking in the inspector, named greenballlayer, blueballlayer, redballlayer. Now select the balls one by one and assign them to the layers accordingly (blue to blue etc.). Now -
public GameObject redBall, blueBall, greenBall;
public LayerMask greenBallLayerMask;
The greenBallLayerMask will only check the collider of the gameobject associated with the layer in the inspector. Then select the gameobject with this script. You will see a Green Ball Layer Mask is "nothing" in the inspector. Select greenballlayer from the drop down list instead of nothing. Assign (GameObject redBall, blueBall, greenBall) accordingly in the inspector by dragging the balls one by one. Done. Now -
void FixedUpdate(){
bool greenBallPassed = Physics2D.Linecast (new Vector2(redBall.transform.position.x, redBall.transform.position.y), new Vector2(blueBall.transform.position.x, blueBall.transform.position.y), greenBallLayerMask);
if(greenBallPassed){
//Do your stuff
}
}
Do, the above steps if you need the other lines and layermasking with other balls. Hope it will help you. Tweaks may needed according to your needs. But you will get an idea how to do it.