- Home /
Question by
dyllandry · Jun 28, 2017 at 08:37 PM ·
edgeraycastallphysics2d.raycast
RaycastAll2D Not Working at Distance from (0,0)
I have a 2D game where bubbles float upwards until they are beyond the water's edgeCollider2D
and then they pop. I detect this by using Physics2D.RaycastAll
upwards from each of the bubbles.
Problem: Bubbles farther right than 4.3 units do not detect anything above them.
I highlighted in yellow the bubbles that have position.x
> 4.3 .
RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, Vector2.up, 20);
Debug.DrawRay(transform.position, new Vector2(0, 20), Color.red);
foreach (RaycastHit2D hit in hits)
{
if (hit.transform.tag == "Water")
{
return true;
}
}
return false;
rightmost-bubbles-not-rising.png
(19.6 kB)
Comment
not quite an answer to your question, but you know at which height your edgeCollider2D is. Why don't you just check the bubble's y position and pop them when they're above that?