Skip to content

Commit 7effb5c

Browse files
committed
ServerShipEnvironment: Fix atmosphere detection outside of ship
1 parent b248ea6 commit 7effb5c

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

src/ServerLib/ServerShipEnvironment.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,34 @@ namespace tsom
187187

188188
ServerAtmosphere* ServerShipEnvironment::GetFallbackAtmosphereAtPosition(const Nz::Vector3f& position)
189189
{
190-
// Should (almost) never be called since entities exit the ship when exiting atmosphere
191-
// Atmosphere is handled by multiple entities AtmosphereCarrier
192-
return nullptr;
190+
if (!m_exteriorEnvironment || !m_exteriorEntity)
191+
return nullptr;
192+
193+
auto& ship = GetShip();
194+
195+
bool isInside = false;
196+
for (const auto& [chunkIndices, chunkData] : m_chunkData)
197+
{
198+
if (!chunkData.hullCollider)
199+
continue;
200+
201+
Nz::Vector3f relativePos = position - ship.GetChunkOffset(chunkIndices);
202+
relativePos -= chunkData.hullCollider->GetCenterOfMass(); //< https://jrouwe.github.io/JoltPhysics/index.html#center-of-mass
203+
if (chunkData.hullCollider->CollisionQuery(relativePos))
204+
{
205+
isInside = true;
206+
break;
207+
}
208+
}
209+
210+
if (isInside)
211+
return nullptr; //< Inside the ship but outside of an atmosphere carrier (inside a wall for example)
212+
213+
// Compute the outside position
214+
auto& outsideNode = m_exteriorEntity.get<Nz::NodeComponent>();
215+
216+
EnvironmentTransform outsideTransform(outsideNode.GetPosition(), outsideNode.GetRotation());
217+
return m_exteriorEnvironment->GetAtmosphereAtPosition(outsideTransform.Translate(position));
193218
}
194219

195220
const GravityController* ServerShipEnvironment::GetGravityController() const

0 commit comments

Comments
 (0)