mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
Fix a bug where actor might spwan at invalid position
This commit is contained in:
1 parent
6af384649a
commit
384c13c5ac
2 files changed
+21
-5
No files matched your search
@@ -839,13 +839,23 @@ namespace Pal3.Actor
|
||||
|
||||
var tilePosition = new Vector2Int(command.TileXPosition, command.TileYPosition);
|
||||
|
||||
// Check if position at current layer exists,
|
||||
// if not, auto switch to next layer (if tile at next layer is walkable)
|
||||
// Check if position at current layer exists, if not, auto switch
|
||||
// to next layer (if tile at next layer is valid).
|
||||
// If position at both layers are valid, switch to next layer.
|
||||
// If current layer is not walkable but next layer is walkable.
|
||||
if (_tilemap.GetLayerCount() > 1)
|
||||
{
|
||||
var isTileInsideCurrentLayer = _tilemap.IsTilePositionInsideTileMap(tilePosition, _currentLayerIndex);
|
||||
var isTileInsideAtNextLayer = _tilemap.IsTilePositionInsideTileMap(tilePosition, (_currentLayerIndex + 1) % 2);
|
||||
if (!isTileInsideCurrentLayer && isTileInsideAtNextLayer)
|
||||
bool isTileExistsInCurrentLayer = _tilemap.TryGetTile(tilePosition,
|
||||
_currentLayerIndex, out NavTile tileAtCurrentLayer);
|
||||
bool isTileExistsInNextLayer = _tilemap.TryGetTile(tilePosition,
|
||||
(_currentLayerIndex + 1) % 2, out NavTile tileAtNextLayer);
|
||||
|
||||
if (!isTileExistsInCurrentLayer && isTileExistsInNextLayer)
|
||||
{
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
else if (isTileExistsInCurrentLayer && isTileExistsInNextLayer &&
|
||||
!tileAtCurrentLayer.IsWalkable() && tileAtNextLayer.IsWalkable())
|
||||
{
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,12 @@ namespace Pal3.Scene
|
||||
{
|
||||
tile = default;
|
||||
Vector2Int tilePosition = GetTilePosition(position, layerIndex);
|
||||
return TryGetTile(tilePosition, layerIndex, out tile);
|
||||
}
|
||||
|
||||
public bool TryGetTile(Vector2Int tilePosition, int layerIndex, out NavTile tile)
|
||||
{
|
||||
tile = default;
|
||||
if (!IsTilePositionInsideTileMap(tilePosition, layerIndex)) return false;
|
||||
tile = GetTile(tilePosition, layerIndex);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user