- Home /
2D PolygonCollider/Mesh intersection detection
Hello, I'm working on a project where the user is able to draw shapes or curves during the game is paused (Time.timescale=0). These curves a created via a mesh and after finishing one curve a PolygonCollider2D is added. The user is allowed to draw a unlimited number of shapes and each shape represents a GameObject on its own. The goal: The Script should detect shapes which are intersecting and if so, they should be connected together (present solution with FixedJoint2D).
if (ObjectNumber == 0)
{
return;
}
else
{
var bound0 = trail.GetComponent<PolygonCollider2D>().bounds;
for (int i = 0; i < ObjectNumber; i++)
{
interObject = GameObject.Find("Trail" + i);
var bound1 = interObject.GetComponent<PolygonCollider2D>().bounds;
if (bound0.Intersects(bound1))
{
joint = trail.AddComponent<FixedJoint2D>();
joint.connectedBody = interObject.GetComponent<Rigidbody2D>();
}
}
This is the current solution, but the bounds arent accurate enough and the scrip detects wrong intersections. Example: The trails have been connected with the Joint, but they arent really intersecting. I tried to get the bounds of the Renderer/MeshRenderer but it doesn't worked either. Another approach was with Collider.IsTouching but this works physics based (doesn't work when paused). Any suggestions? Thank you!
Your answer
Follow this Question
Related Questions
2D box colliders not touching but are colliding, how to fix? 0 Answers
Weapon System with collide detection (Helps with script pls)!!! 0 Answers
Why is my collision script not working? 1 Answer
rigidbody2D.addforce in collider 1 Answer
Detecting collisions between objects from another c# script 1 Answer