1
我正在使用raycast來確定ropejoint的錨點位置。通過使用一些簡單的繪製調用,我可以看到在raycast返回點可靠地創建了ropejoint。我的問題在於迴歸點。它偶爾會穿過身體,在對面的邊界上返回一個點,有時會在身體內部返回。當它發生時,它似乎總是失敗,也就是說,如果我投射了重複通過的光線,它會繼續通過並返回相同的不正確點。這使我相信我的身體存在問題。我正在使用TextureToBody轉換器來處理有問題的機構。Raycast在VB.NET.XNA中使用Farseer Physics丟失檢測結果
另一個較小的問題是,我必須在每個方向上從我的關節位置減去10/64以準確連接。我不知道爲什麼會發生這種情況。 (64pixels =1米是我使用的轉換比率)
光線投射方法:
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