- Home /
Physics2D.Raycast not working,My Physics2D.Raycast is not working.
So I am trying to check the surrounding of my object, using an array of positions to check and using it to calculate the direction my raycast should go. Yet everytime I try to move the object its trying to detect even to the point of overlapping, it still does not work. I've triple checked the layer mask, the tag, the colliders its using, everything. yet I cannot find what seems to be the problem.
Private void Update()
{
for (int i = 0; i < positions.Count; i++)
{
hit = Physics2D.Raycast(transform.position, (new Vector2(transform.position.x, transform.position.y) - positions[i]).normalized, 15f, 1 << LayerMask.NameToLayer("ground"));
if(hit.collider != null) { if (hit.collider.tag.Equals("planet")) { print("hit"); } } } }
,I have tried everything, from layer masks to infinite distance from the object I'm trying to detect. Even from putting it right beside the source. I have an array of positions where to check from its North, NW, W, SW, SE,E,NE.
private void Update()
{
for (int i = 0; i < positions.Count; i++)
{
hit = Physics2D.Raycast(transform.position,(new Vector2(transform.position.x,transform.position.y) - positions[i]).normalized, 15f, 1 << LayerMask.NameToLayer("ground"));
if(hit.collider != null)
{
if (hit.collider.tag.Equals("planet"))
{
print("hit");
}
}
}
}
Your answer
Follow this Question
Related Questions
Can't find the null reference 1 Answer
RaycastHit2D problem with PolygonCollider2D 2 Answers
2D Raycast Layer Mask not working 1 Answer