Question by
Janneman96 · Mar 12 at 01:37 PM ·
collider2dcast
What am I doing wrong with the Collider2D.Cast function?
I have this code:
1 var hitResults = new RaycastHit2D[10];
2 var hitX = collider.Cast(new Vector2(desiredX, 0), bodyFilter, hitResults);
3 //var test = new Collider2D[10];
4 //hitX = collider.OverlapCollider(bodyFilter, test);
5 if (hitX == 0)
6 {
7 transform.Translate(desiredX, 0, 0);
8 }
The bodyFilter is a ContactFilter2D.
When I run the code like this, the character ignores all collisions with walls. When I uncomment line 4 and 5, the character stops moving horizontally once it is colliding with a wall.
What's wrong about my call to the Collider2D.Cast function?
Comment