Libgdx Isometric grid point and collision block check

Ive basically got an isometric map, and my player was constantly fixing and centered in the middle of the screen. To check for collisions, I first convert the point to the coordinates of the map, and then use these coordinates to check whether the fragment itself, depending on how the player moves, has properties containing the word "blocked". If so, stop moving (go back to oldposY and oldposX) Well, it works, sort of. My player stops at tiles that do not contain “locked”. Each time a player stops in this video, the code discovers that he hit tiles with properties marked “blocked”, however this is incorrect.

Here is a video showing the problem in action: http://youtu.be/FG12KGw_eg4

I print my x, y coordinates in the upper left corner of the screen, and this shows that my x and y are increasing or decreasing, even if I travel in the same direction. For example, if I go only to the right side of the screen, x And y increase if you think that only X should increase. This is true for any direction, up, up, right, left, up, left, etc. I don't know if this helps, but I think it means the MapUtils.toIsometricGridPoint function is not working properly. Will this simplify this at all, knowing that my player character is constantly fixed in the center of the screen?

On with code. Here is my MapUtils.toIsometricGridPoint method

/** converts point to its coordinates on an isometric grid
    *  @param point the point to convert
    *  @param cellWidth the width of the grid cells
    *  @param cellHeight the height of the grid cells
    *  @return the given point converted to its coordinates on an isometric grid */

/** @see #toIsometricGridPoint(Vector2, float, float) */
   public static Vector3 toIsometricGridPoint(Vector3 point, float cellWidth, float cellHeight) {
      Vector2 vec2 = toIsometricGridPoint(point.x, point.y, cellWidth, cellHeight);
      point.x = vec2.x;
      point.y = vec2.y;
      return point;
   }

Player, , toIsometricGridPoint:

    private boolean isCellBlocked(float x, float y) {
    Vector3 touch = new Vector3(x, y, 0);
    Play.camera.unproject(touch); //the touch variable has nothing to do with touch atm, it just what it called.
    MapUtils.toIsometricGridPoint(touch, collisionLayer.getTileWidth(), collisionLayer.getTileHeight()); //collisionlayer is a layer on my map obviously
    Cell cell = collisionLayer.getCell((int) touch.x, (int) touch.y);
    return cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey("blocked"); //a string Ive marked some tiles properties with in my tiled map editor
    }

, , , ( ):

public boolean collidesRight() {
        for(float step = 0; step < getHeight(); step += collisionLayer.getTileHeight() / 2)
                if(isCellBlocked(getX() + getWidth(), getY() + step)){
                   Gdx.app.log("Found Blocked Tile", "Yes");
                   return true;
                }

             return false;

, , "" , , . , - , .

+3

All Articles