Page 1 of 1

raycast

Posted: Wed Nov 20, 2013 4:21 pm
by vkreal
I am having trouble detecting distance using raycast when its behind another body. Is it possible to raycast to figure out distance where the body is behind another?


Thanks!

Re: raycast

Posted: Wed Nov 20, 2013 4:45 pm
by iforce2d
Yes. If you are using b2World::RayCast, you can return 1 from the ReportFixture function to make it keep going until you get a report for the fixture you are interested in.

But if you already know which fixture you want, you can use b2Fixture::RayCast, so that the ray does not even consider other fixtures in the first place - that would probably be faster too.

Re: raycast

Posted: Wed Nov 20, 2013 5:28 pm
by vkreal
Awesome! Thanks for quick reply and solutions. I will try out b2Fixture::RayCast, but i did try b2World::RayCast return 1 in ReportFixture to find correct fixture but didn't seem to work, maybe i didn't do it right.

Re: raycast

Posted: Wed Nov 20, 2013 5:38 pm
by iforce2d
When you return 1 from the ReportFixture it will continue to loop through all of the fixtures that the ray hits. You will also need to check that the fixture being reported is the one you want, and the order the fixtures are reported can be any order. If you just record the first hit, or the last hit etc, it may be some other fixture.