- Home /
trouble with collider2D.cast
RaycastHit2D[] test = Collider2D.Cast(new Vector2(scale_x, 0), LayerMask.GetMask("Wall"), whereto, false);
This code is not working given the error on LayerMask.GetMask("Wall") saying its not possible to convert an "int" into a "UnityConvert.Raycasthit2D[]" im really confused... since i thought i was supposed to place a contactFilter there... can anyone help me with this one?
Answer by vJoeyz · Dec 20, 2018 at 08:48 PM
Collider2D.Cast()
returns an int with the number of results, so this error is expected here. I think you are looking for something like Physics2D.RaycastAll()
.
im trying to avoid raycast since it doesnt work very well with the physics of my game... i need something that involves the whole hitbox of my character... are there any other options avaible or any fixes to this problem?
Answer by Mouroz · Dec 20, 2018 at 11:06 PM
Alright i got some knowledge of how the Collider2D.Cast()
works! It seems that just live vJoeyz said it returns an int with the number of results... the problem is that im trying to just like a RaycastHit2D[] test = Physics2D.RaycastAll()
get a array of all objects found so then i can change my position... Its crucial that i dont use anything like raycast on my code since it might cause the player to get pushed inside a obstacle (just like it happened many times before with my older version of my code using raycast) and so i must use something that doesnt involve only a line... but the size of the player collider... Are there any other codes that might help me doing this calculation or any other way using Collider2D.cast
so i can get an array of all the objects collided and not the ammount of objects found?
Your answer
