1

ロープジョイントのアンカー位置を決定するためにレイキャストを使用しています。いくつかの単純なドロー コールを使用すると、レイキャストが返された時点でロープ ジョイントが確実に作成されていることがわかります。私の問題はリターンポイントにあります。ボディを通過することもあり、反対側の境界上のポイントを返したり、ボディの内部に到達することもあります。つまり、繰り返し通過するレイをキャストすると、通過し続け、同じ間違ったポイントを返します。これは、私の体に問題があると私に信じさせます。問題のボディに TextureToBody コンバーターを使用しています。

もう1つの、より小さな問題は、関節の位置から各方向に10/64を差し引いて、正確に取り付ける必要があることです. なぜこれが起こっているのか分かりません。(64 ピクセル = 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
4

1 に答える 1

0

私のFarseerの使用に基づいて、RayCastによって返されたすべてのポイントのリストを作成し、それらを距離でソートする必要があります.

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、これが意図したことであることを確認する必要があります。

于 2012-11-16T17:15:21.917 に答える