1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 19:32:49 +01:00

Fix character inWater behaviour

This commit is contained in:
Daniel Evans 2015-04-01 04:36:52 +01:00
parent 15e2082ebc
commit 4faf07cba3
4 changed files with 25 additions and 16 deletions

View File

@ -45,7 +45,7 @@ public:
*/
float mHealth;
bool _inWater;
bool inWater;
/**
* @brief stores the height of water at the last tick
@ -60,7 +60,7 @@ public:
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, ModelRef model)
: _lastPosition(pos), _lastRotation(rot), position(pos), rotation(rot),
model(model), engine(engine), animator(nullptr), skeleton(nullptr), mHealth(0.f),
_inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true),
inWater(false), _lastHeight(std::numeric_limits<float>::max()), visible(true),
lifetime(GameObject::UnknownLifetime)
{}
@ -139,7 +139,7 @@ public:
virtual bool isAnimationFixed() const { return true; }
virtual bool isInWater() const { return _inWater; }
virtual bool isInWater() const { return inWater; }
virtual void tick(float dt) = 0;

View File

@ -230,7 +230,15 @@ void CharacterObject::updateCharacter(float dt)
float wh = engine->gameData.waterHeights[wi];
auto ws = getPosition();
wh += engine->gameData.getWaveHeightAt(ws);
if( ws.z < wh ) {
// If Not in water before
// If last position was above water
// Now Underwater
// Else Not Underwater
// Else
// Underwater
if( ! inWater && ws.z < wh && _lastHeight > wh ) {
ws.z = wh;
btVector3 bpos(ws.x, ws.y, ws.z);
@ -240,13 +248,14 @@ void CharacterObject::updateCharacter(float dt)
physObject->setWorldTransform(wt);
physCharacter->setGravity(0.f);
_inWater = true;
inWater = true;
}
else {
physCharacter->setGravity(9.81f);
_inWater = false;
inWater = false;
}
}
_lastHeight = getPosition().z;
}
}

View File

@ -65,19 +65,19 @@ void InstanceObject::tick(float dt)
wH = engine->gameData.waterHeights[hI];
wH += engine->gameData.getWaveHeightAt(ws);
if( vH <= wH ) {
_inWater = true;
inWater = true;
}
else {
_inWater = false;
inWater = false;
}
}
else {
_inWater = false;
inWater = false;
}
}
_lastHeight = ws.z;
if( _inWater ) {
if( inWater ) {
float oZ = -(body->collisionHeight * (dynamics->bouancy/100.f));
body->body->activate(true);
// Damper motion

View File

@ -245,24 +245,24 @@ void VehicleObject::tickPhysics(float dt)
// and was not underwater here in the last tick
if( _lastHeight >= wH ) {
// we are for real, underwater
_inWater = true;
inWater = true;
}
else if( _inWater == false ) {
else if( inWater == false ) {
// It's just a tunnel or something, we good.
_inWater = false;
inWater = false;
}
}
else {
// The water is beneath us
_inWater = false;
inWater = false;
}
}
else {
_inWater = false;
inWater = false;
}
}
if( _inWater ) {
if( inWater ) {
// Ensure that vehicles don't fall asleep at the top of a wave.
if(! physBody->isActive() )
{