Hi guys, I have a weird problem right now where the entity will follow the path perfectly, that is until he has to go down. I’ve included a picture to show what I mean.
Pink = path the entity HAS taken
blue = path entity should follow (This is just a path made in Tiled)
red = entity
For some reason he skips a large section and then stops moving at that spot. This happens whenever the path goes down. I think my problem might be somewhere in the path creation area? Though i’m not sure D:
http://s8.postimg.org/dc0w9zsg5/Path_Example.png
Below is the code that sets the path to follow:
TiledMapTileLayer layer = (TiledMapTileLayer) levelMap.getLayers().get("Path Layer");
for(int x=0; x < layer.getWidth(); x++){
for(int y=0; y < layer.getHeight(); y++){
Cell cell = layer.getCell(x, y);
if(cell != null){
TiledMapTile currentTile = cell.getTile();
if(currentTile != null && currentTile.getProperties().containsKey("Path")){
float tx = x * layer.getTileWidth();
float ty = y * layer.getTileHeight();
levelPath.addPathTile(tx, ty);
}
}
}
}
And this is the code that makes the entity follow the path:
Vector2 direction = new Vector2(path.getPath().get(entity.getPathIndex()).getX() - entity.getX(), path.getPath().get(entity.getPathIndex()).getY() - entity.getY());
direction.nor();
entity.setX(entity.getX() + direction.x);
entity.setY(entity.getY() + direction.y);
if(entity.getX() == path.getPath().get(entity.getPathIndex()).getX() && entity.getY() == path.getPath().get(entity.getPathIndex()).getY()){
entity.setPathIndex(entity.getPathIndex() + 1);
}