4
\$\begingroup\$

I followed the tutorial here to generate box2d bodies from a tiled map and that worked fine.... for orthogonal tiled maps. Unfortunately isometric maps use their own coordinate system where (0, 0) is at the leftmost corner of the map, and this causes the bodies to be in the wrong place.

I tried implementing a transformation matrix or just transforming the body but I don't think that is possible (or at least I could never find a way). How else can this be solved? Here is the relevant method that needs to be changed:

private Shape getPolygon(PolygonMapObject polygonObject) {
    PolygonShape polygon = new PolygonShape();


    float[] vertices = polygonObject.getPolygon().getTransformedVertices();

    float[] worldVertices = new float[vertices.length];

    for (int i = 0; i < vertices.length; ++i) {
        worldVertices[i] = vertices[i] / units;
    }

    polygon.set(worldVertices);
    return polygon;
}

As you can see I need a way to convert the isometric coordinates to game coordinates using just plain math or something else like a matrix. I think the only line needing to be changed is the line in the for loop.

\$\endgroup\$
  • \$\begingroup\$ did you ever solve it? I'm having the same issue \$\endgroup\$ – Lior Iluz Apr 27 '16 at 10:12
  • \$\begingroup\$ Did you ever end up fixing this? \$\endgroup\$ – Troy Dickie Apr 6 '17 at 6:28
  • \$\begingroup\$ Yes I did end up solving I think. I can't remember how because I ended up converting my app to 3D because it made things much easier, but I will look through my old code and see if I can find the solution \$\endgroup\$ – Vincent Williams Apr 7 '17 at 17:01
1
\$\begingroup\$

I had the same question that I have been able to answer here Box2d collision on isometric maps built in Tiled

Get the vertices out of the polygon and transform them from orthographic space to isometric with code like this.

public static Vector2 TwoDToIso(Vector2 point){
   Vector2 vel2 = new Vector2();

   vel2.x = point.x - point.y;
   vel2.y = -(point.x + point.y) / 2;
   return vel2;
}

I had to minus the y value in my example because my object was flipped incorrectly.

I hope this helps

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.