This project has moved. For the latest updates, please go here.

Raycasts and Missed Detections

Topics: Developer Forum, User Forum
Dec 15, 2011 at 4:41 AM

I'm using a raycast to determine the anchor location of a ropejoint. By using some simple draw calls, I can see that the ropejoint is being reliably created at the point the raycast returns. My problem lies in the return point. It occasionally passes through a body, returning a point on the opposite border, and sometimes inside the body. It seems to consistently fail when it does, that is to say, if I cast a ray that passes through repeatedly, it continues to pass through. This leads me to believe there is a problem with my bodies. I am using the TextureToBody convertor for the bodies in question. Is that the problem?

Another, lesser, issue is that i have to subtract 10/64 in each direction from my joints position to have it accurately attach. I have no idea why this is happening. (64pixels=1meter is the conversion ratio I'm using)

Code Snippet:

        Private Sub castRay(startPoint As Vector2, direction As Vector2)
            direction *= 25
            direction.Y = (-direction.Y)
            world.RayCast(Function(fixture As Fixture, point As Vector2, normal As Vector2, fraction As Single)
                              Dim body As Body = fixture.Body

                              ropeContactFixture = fixture
                              ropeContactPoint = point
                              ropeJoint = New RopeJoint(Me.body, fixture.Body, New Vector2(0, 0), point - ropeContactFixture.Body.Position - (New Vector2(10, 10) / 64))
                              Return 0
                          End Function, startPoint, startPoint + direction)
        End Sub


As another thought, which I'm much less worried about getting an answer to right now, since I can't get regular raycasts working, but am nonetheless curious about: is there a reliable method to casting a curved ray? Without giving it too much though, I suppose a recursive function could probably achieve this...?

Dec 19, 2011 at 9:49 AM

Take a look to this post, probably it will fix your issue: