Try to better handle small 'gaps' (or perhaps floating point

rounding errors) in tracks that can cause odd physics behaviour
(e.g. being able td drive upp the walls).
This commit is contained in:
hiker 2017-03-30 00:08:30 +11:00
parent 6f293af93a
commit 1cd5bb66c9
2 changed files with 18 additions and 6 deletions

View File

@ -192,7 +192,8 @@ void btKart::resetSuspension()
// ----------------------------------------------------------------------------
void btKart::updateWheelTransformsWS(btWheelInfo& wheel,
bool interpolatedTransform)
bool interpolatedTransform,
float fraction)
{
wheel.m_raycastInfo.m_isInContact = false;
@ -203,7 +204,7 @@ void btKart::updateWheelTransformsWS(btWheelInfo& wheel,
}
wheel.m_raycastInfo.m_hardPointWS =
chassisTrans( wheel.m_chassisConnectionPointCS );
chassisTrans( wheel.m_chassisConnectionPointCS*fraction );
wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.getBasis() *
wheel.m_wheelDirectionCS ;
wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.getBasis() *
@ -213,7 +214,7 @@ void btKart::updateWheelTransformsWS(btWheelInfo& wheel,
// ----------------------------------------------------------------------------
/**
*/
btScalar btKart::rayCast(unsigned int index)
btScalar btKart::rayCast(unsigned int index, float fraction)
{
btWheelInfo &wheel = m_wheelInfo[index];
@ -229,7 +230,7 @@ btScalar btKart::rayCast(unsigned int index)
m_chassisBody->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
updateWheelTransformsWS( wheel,false);
updateWheelTransformsWS( wheel,false, fraction);
btScalar max_susp_len = wheel.getSuspensionRestLength()
+ wheel.m_maxSuspensionTravel;
@ -391,6 +392,16 @@ void btKart::updateVehicle( btScalar step )
rayCast( i);
if(m_wheelInfo[i].m_raycastInfo.m_isInContact)
m_num_wheels_on_ground++;
else
{
// If the original raycast did not hit the ground,
// try a little bit (5%) closer to the centre of the chassis.
// Some tracks have very minor gaps that would otherwise
// trigger odd physical behaviour.
rayCast(i, 0.95f);
if (m_wheelInfo[i].m_raycastInfo.m_isInContact)
m_num_wheels_on_ground++;
}
}
// Test if the kart is falling so fast

View File

@ -150,7 +150,7 @@ public:
void reset();
void debugDraw(btIDebugDraw* debugDrawer);
const btTransform& getChassisWorldTransform() const;
btScalar rayCast(unsigned int index);
btScalar rayCast(unsigned int index, float fraction=1.0f);
virtual void updateVehicle(btScalar step);
void resetSuspension();
btScalar getSteeringValue(int wheel) const;
@ -169,7 +169,8 @@ public:
const btWheelInfo& getWheelInfo(int index) const;
btWheelInfo& getWheelInfo(int index);
void updateWheelTransformsWS(btWheelInfo& wheel,
bool interpolatedTransform=true);
bool interpolatedTransform=true,
float fraction = 1.0f);
void setAllBrakes(btScalar brake);
void updateSuspension(btScalar deltaTime);
virtual void updateFriction(btScalar timeStep);