RayCastCallback ray sometimes goes trough first fixture.

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Posts: 1
Joined: Fri Jan 27, 2017 8:23 am

RayCastCallback ray sometimes goes trough first fixture.

Postby lazarantal » Fri Jan 27, 2017 12:55 pm


I have a polygon object composed of multiple fixtures (see attachment). My problem is that the Box2D raycasts which are hitting this object, behave unpredictable. For example, a raycast coming from below, usually stops at the outer edge (marked with the red dot), but sometimes it goes trough the first fixture and stops at the next one, marked by the yellow dot. Here is my raycast function:

Code: Select all

callbackRayCast = new RayCastCallback()
         public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction)
            // test
            return 0;

I am always returning 0, to stop at the first fixture. Could you tell me, why it happens sometimes that the ray "ignores" the first fixture and it stops at the next one?

Any help is appreciated.

RayCast.PNG (14.7 KiB) Viewed 420 times

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo

Re: RayCastCallback ray sometimes goes trough first fixture.

Postby irresistible force » Sun Mar 26, 2017 9:30 am

Returning zero means that the ray is now zero length, so all subsequent raycasts will encounter nothing. You should be returning the fraction value, to clip the ray to the point where it hit the fixture.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest