Search code examples
c#xnagame-physicsfarseer

Moving A Body With A Texture


I am using Farseer Physics Engine to build a "Monster Dash" like game targeted for the PC using C# and XNA, I am trying to move a body with it's texture, the texture is built from parts so they all should move together, basically it looks like this:

    public void Update()
    {
        tilingFloorPosition.X += (floorMoveSpeed / MeterInPixels);
        _tilingFloorBody.Position = tilingFloorPosition;

        // Update the textures position
        for (int i = 0; i < texturePositions.Length; i++)
        {
            texturePositions[i].X += floorMoveSpeed;
        }
    }

But whenever my player lands on top of the floor he just goes through it like there is nothing there, what am I doing wrong?


Solution

  • If the player is falling through the floor then I can only assume that either the floor's body isn't actually in position, or the two bodies are not colliding. Can you confirm that the floor is indeed positioned correctly? If you're able, turn on the Farseer Debug View. If so, then the collision must not be occurring.

    Check:

    • That both the player and the floor are not sensors.
    • That they are not within the same CollisionCategory and at least one of them is included within the others CollidesWithCategory.
    • That you have not added one of the bodies to the others IgnoreBody list.
    • That the body types will collide. See: Farseeer Body Types.

    Also, it may be worth noting that it is possible that manually setting the position could skip the collision. Try instead setting the LinearVelocity.