diff --git a/unit.cpp b/unit.cpp index fe1db3a..fc021e4 100755 --- a/unit.cpp +++ b/unit.cpp @@ -513,14 +513,21 @@ namespace battleship{ //TODO select only the closest cells based on unit size void Unit::placeAt(Vector3 p){ + Map *map = Map::getSingleton(); + + if(type == UnitType::LAND){ + vector res = RayCaster::cast(Vector3(p.x, 100, p.z), -Vector3::VEC_J, vector{map->getNodeParent()->getChild(0)}, 0, 20); + p.y = res[0].pos.y; + } + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); //check twice in case the unit is warped over a long distance - if(activeState) Map::getSingleton()->blockCells(this); + if(activeState) map->blockCells(this); GameObject::placeAt(p); if(activeState){ - Map::getSingleton()->blockCells(this); + map->blockCells(this); if(activeState->getPlayer()) Map::Minimap::getSingleton()->updateImage(); diff --git a/vehicle.cpp b/vehicle.cpp index 68d5a43..96e3f47 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -255,7 +255,7 @@ namespace battleship{ int dest = map->getCellId(destPos); - if(type != UnitType::UNDERWATER && fabs(destPos.y - cells[dest].pos.y) > .1) return; + if(type != UnitType::UNDERWATER && type == UnitType::SEA_LEVEL && fabs(destPos.y - cells[dest].pos.y) > .1) return; if(cells[dest].blockedBy){ vector surrCellIds = map->getSurroundingCells(cells[dest].pos, 1);