I’m trying to make a chess-like board game, where there’s a board comprised of tiles, and each piece can move between the tiles. But the thing I’m stumped with is how do I check whether a tile is blocked by something on another tile? So if there’s a piece that can move two spaces forwards, but there’s another piece on the tile in front of it, how do I prevent it from moving to the tile behind that occupied tile?
Beyond just moving in straight lines, I also have abilities that work around radii. So the ability can target anyone within, say, 5 tiles, but it can’t target a piece if there’s another piece blocking it.
Has anyone encountered a system like this before, or have any ideas? Any advice would be greatly appreciated!
Beyond just moving in straight lines, I also have abilities that work around radii. So the ability can target anyone within, say, 5 tiles, but it can’t target a piece if there’s another piece blocking it.
Line trace in the desired direction and with desired magnitude and see if you hit something.
I thought of that, but I was worried it might not work if different pieces have different collision settings or move in unique patterns, like a knight in chess.
this is way more complex than one expects. I think you need to encapsulate functionality for each board square. for example a board square may know if a piece is on top, what that piece, if it allows other pieces to jump over, or if you can capture it, stuff like that.
or you may use a different approach, create a top down manager that keeps track of the board and the pieces.
I suggest finding tutorials about how to create a chess game not necessarily for unreal, and figure out the logic first then get back and try to adapt on unreal.
you can also look into turn based games logic, they have a board and various patterns on how to deal with units and the like. not necessarily for a chess game but same stuff should apply