- Home /
Question by
starpolo98 · Nov 19, 2018 at 03:05 PM ·
raycastraycastingraycasthit2d
Get the object behind my gameobject by rayCast
Hi, I'm using rayCast in order to get the object behind my gameObject. The probleme is that it returns only my gameObject. Do you know how to solve it in order to get the object behind my gameobject ? thks :)
RaycastHit2D hitInformation = Physics2D.Raycast(transform.position, Camera.main.transform.forward);
Comment
Best Answer
Answer by hexagonius · Nov 19, 2018 at 03:14 PM
use RaycastAll instead and filter your object out. the remaining result should contain the one you're looking for
Thank you ! I changed the code with this line and it all works just fine :D
RaycastHit2D[] hitInformation = Physics2D.RaycastAll(transform.position, Camera.main.transform.forward,$$anonymous$$athf.Infinity, gridLayer);
Your answer
![](https://koobas.hobune.stream/wayback/20220612182407im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a problem with my raycast? 1 Answer
Is there a problem with my raycast? 1 Answer
My Raycasts seem to sometimes miss 0 Answers
2d Raycast not work 1 Answer
What is the best way to raycast mutliple rays over a line 1 Answer