bilal ali8
bilal ali8

Reputation: 1

How can I add 3d collision in an isometric tile map in Monogame

So I'm trying to add a 3d collision in my 2d isometric collision. I want to use Vector3 to help me. The z position will be the depth. But i tried it and it does not work. Is there any way of adding a 3d collision if you know the tile position and the player position. if there is a 10 by 10 tile isometric grid and a depth of 1, and the player (depth 1) is in the middle, the tile behind the player head and body must not collide with tile behind which is a ground, only the legs or bottom middle part of the player must collide. in this picture enter image description here it shows a tile (which is the player with a ground tile) colliding with other tiles which is shown in red, however the collision is to spread out, and the tile behind the player must not collide ,

I tried using many method including rectangle collision, diamond collision and Bounding box collision. All of this method did not work, I think it because of me using the formula or method wrong.

This 3 method, shows how i make a Bounding box

public BoundingBox GetBoundingBox()
{
    Vector3 min = new Vector3(Position.X, Position.Y , Position.Z  );
    Vector3 max = new Vector3(Position.X + 16,
                              Position.Y + 18,
                              Position.Z + 1); // Adjust Z as needed for height

    return new BoundingBox(min, max);
}


public bool IsometricCollsion(BoundingBox box1,BoundingBox box2)
{

    if (box1.Intersects(box2))
    {
        return true;
    }

    else
    {
        return false;
    }



}
for (int i = 0; i < TileGroup.Count; i++)
{
    TileGroup[i].Update(MoveX, MoveY, Tilescale);

    if (Login.IsometricCollsion(TileGroup[i].GetBoundingBox(), player.GetBoundingBox()) == true)
    {
        TileGroup[i].color = Color.Red;
    }

    else if (Login.IsometricCollsion(TileGroup[i].GetBoundingBox(), player.GetBoundingBox()) == false)
    {
        TileGroup[i].color = Color.White;
    }

}

Upvotes: 0

Views: 33

Answers (0)

Related Questions