- Home /
Question by
USkittles · Aug 15, 2015 at 03:38 AM ·
c#raycastinconsistent
Raycast2D is inconsistent
I have blocks which are casting above them to check if there is an object. This is so that they can change their sprite if there is space above them (eg grass blocks). The issue with this, is that some blocks will work fine and some wont. The ones that don't work are always the same, but I can't see a pattern on which they are. Also, sometimes if I place random blocks in other places, blocks which previously didn't work will suddenly function properly. Weird.
I don't know what else you tell you, but I'm hoping someone has experienced this before and can help me out.
if (Physics2D.Raycast (new Vector2 (transform.position.x, transform.position.y + 2), new Vector2 (transform.position.x, transform.position.y + 2.2f))) {
Debug.Log ("Hit");
}
else
{
Debug.Log ("Didn't Hit");
Vector3 pos = transform.position;
Instantiate (design1, pos, Quaternion.identity);
}
Each block is 2x2, and they are placed next to each other.
Thanks
Comment