I have a star in the scene (using SM2). Each point has a box collider attached to it (no rigibody). The points are children of a main object (this one has rigibody). How can i detect if two points of the star land on something and then start counting?
My code using OnCollisionStay works, but it works even when there is only one point land on something else.
If the whole object is a rigidbody all colliders that are attached to child objects act as one compound collider. OnCollsionStay should work but in addition just check that you have two collisions. Take a look at the collisioninfo you get passed inside OnCollisionStay().
function OnCollisionStay(collision : Collision)
{
if (collision.contacts.length >= 2)
{
// I'm colliding with 2 points
}
}
ps. in C# the "length" property is upcase: "Length"
EDIT:
To see where your colliders collide you can show the collision points. This example draws a line from the collision point along the hitnormal vector:
function OnCollisionStay(collision : Collision)
{
if (collision.contacts.length >= 2) {
// I'm colliding with 2 points
}
// Only for Debugging, in the editor you have to enable "Gizmos" at
// the top of scene view
for (var currentPoint : ContactPoint in collision.contacts) {
Debug.DrawRay(currentPoint.point,currentPoint.normal*2,Color.red);
}
}
This for-loop should be removed in your final build to reduce overhead. It's not possible to draw lines like that in any kind of build (web/standalone/..). It's only for debugging in the editor.