I want to know, how to get no collision inside an object. I have a big circle and inside the circle is a smaller square. When the game starts, the circle is scaling down. And what i want, is to check the collision, if circle is touching or is inside the square.
Can you please help me ? Thank you
As far as I know there is no built-in way of achieving this in Unity (There is also not a built-in way of detecting whether a collider is fully inside another collider or not).
If I understood you correctly your circle is going to shrink and when it reaches this point
you want to do something e.g. execute some code.
The way you could make it work for a circle and a square just based on maths would be this:
If the sides of your square are of length
a
and your circle has a decreasing radius ofr
, then at the moment you see in the image above the relation between the two of them is:So you could check
if (r <= a / Mathf.Sqrt(2))
in theUpdate
function and based on that call some function. (Maybe add another boolean to ensure the function only gets called once.)You can get your sprite widths using
The radius of your circle would then obviously be half the width of the circle sprite.
You should probably also store the
SpriteRenderer
in a variable once instead of callingGetComponent
on every frame.For an equilateral triangle the equation would be
where
a
is the length of the triangle's side.