rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 261 forks source link

Can add an object which is not block and considered in path finding? #197

Closed john-trovalto closed 3 years ago

john-trovalto commented 3 years ago

Hi,

Can we add an object to the board which can't be block shape and could be consider in path finding?

For example, consider an example of football game. Chess will be the players, referee will be the block object and the ball will be a object which will be overlapped by the players.

Any assistance you can provide would be greatly appreciated.

rexrainbow commented 3 years ago

PathFinding

Try to set occupiedTest and blockerTest to false in config of PathFinder. Then the path searching won't excluded any tile. Then customize the cost function, get chess at the curTileXY position

var chess = board.tileXYZToChess(curTileXY.x, curTileXY.y, tileZ);

or

var chessArray = board.tileXYToChessArray(tileX, tileY);

return cost according to chess (null if no chess there, or a player chess, etc)

Moving chess

Because that a tile position (tileX, tileY, tileZ) only can have a chess (put a chess to an occupied tile position will kick old one out of board). To avoid that, you might set tileZ to an unique number for each chess. Or set sneak to true in config of moveTo behavior, if using it to move chess.

john-trovalto commented 3 years ago

So are you suggesting to put the ball as a chess object not as a shape?

rexrainbow commented 3 years ago

You might add any game object as a chess by board.addChess(gameObject, tileX, tileY, tileZ, align). Shape is a kind of game object, too.

john-trovalto commented 3 years ago

@rexrainbow Thanks, I just added the sprite and it is working fine. If I add physics to it, the sprite is not visible in the board. So just wanted to confirm if the physics game object will work or not?

Update: got it working. Can I add physics bounds around the board so that ball object keep within the gameboard?

rexrainbow commented 3 years ago

Board plugin does not have 'bounds' properties, sorry.

john-trovalto commented 3 years ago

@rexrainbow No worries. I managed to add boundaries. Thanks a lot for help.