scratchyrice
28-03-2009 17:03:34
This snippet comes directly from my game engine, But im sure the bright minds on here can easily figure it out. This code is used for buoyancy, Of dynamic waves like the hydrax system. I will soon put up a video demonstrating the effect.
I hope someone finds this snippet useful
Cheers
Scratchy
//Get the current wave height
_waveHeight = _myPhysicsSystem->getSceneManager()->environment->getOceanSystem()->getHeight(_currentActorPosition->x, _currentActorPosition->z);
//Calculate the distance from the wave
_distanceFromWave = _currentActorPosition->y - _waveHeight;
//Check to see if the actor is below the current wave level
if (_distanceFromWave < 0)
{
//Calculate a buoyancy force.
_forcey = ((-_myPhysicsSystem->getGravity().y) * _currentActor->_getPhysXActor()->getMass())
+ (-_currentActor->_getPhysXActor()->getLinearVelocity().y * _currentActor->_getPhysXActor()->getMass())
+ ((_distanceFromWave) * _currentActor->_getPhysXActor()->getMass());
//Dampen the force, If needed. This is done so when a wave level drops, The boat does not seemingly plumet to its death.
if (-_distanceFromWave <= _currentActorHeight / 2)
{
_dampingPercentage = (_distanceFromWave / (_currentActorHeight / 2));
_dampingPercentage = _forcey * (-_dampingPercentage);
_forcey = _dampingPercentage;
}
_currentActor->_getPhysXActor()->addForce(Ogre::Vector3(0, _forcey, 0) , NxForceMode::NX_FORCE, true);
}
I hope someone finds this snippet useful
Cheers
Scratchy