2011-12-17 6 views
1

私はロープジョイントのアンカー位置を決定するためにレイキャストを使用しています。簡単な描画呼び出しを使用することで、レイプジョイントがレイ・キャストが返すポイントで確実に作成されていることがわかります。私の問題はリターンポイントにある。時には体を通過し、反対側の境界線上の点を返します。時には体の内側に戻ります。それは一貫して失敗するように見える、つまり、繰り返し通過する光線を投射すると、それは通過して同じ不正な点を返す。これは私の体に問題があると信じさせてくれます。問題のボディにTextureToBodyコンバーターを使用しています。RaycastにVB.NET.XNAのFarseer Physicsを使用した検出がありません

もう少し小さい問題は、関節の位置から各方向に10/64を差し引いて正確に取り付けなければならないということです。なぜこれが起こっているのか分かりません。

あなたはレイキャストによって返されたすべてのポイントのリストを作成して、距離によってそれらを並べ替える必要がありますFarseerの私の使用に基づいて
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 

答えて

0

レイキャスト法(64pixels = 1メートルは、私が使用している変換比です) 。

はFarseersコードから撮影 -

 Ray-cast the world for all fixtures in the path of the ray. Your callback 
    controls whether you get the closest point, any point, or n-points. 
    The ray-cast ignores shapes that contain the starting point. 

    Inside the callback: 
    return -1: ignore this fixture and continue 
    return 0: terminate the ray cast 
    return fraction: clip the ray to this point 
    return 1: don't clip the ray and continue 

ですから、光線に沿った点のリストを作成し、最も近いを見つけ、その後、ロープを作ることができる必要があり、この知識を使用して。

なぜ私はdirection.Yを反転させているのか分かりませんが、これが意図したとおりであることを確認してください。

関連する問題