aligning placed units' height with the surface

This commit is contained in:
devZoGok
2025-09-22 18:27:16 +03:00
parent 6eef89f258
commit 00af4433d3
2 changed files with 10 additions and 3 deletions
+9 -2
View File
@@ -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<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(p.x, 100, p.z), -Vector3::VEC_J, vector<Node*>{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();
+1 -1
View File
@@ -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<int> surrCellIds = map->getSurroundingCells(cells[dest].pos, 1);