separate zipper velocity change from suspension/turning impulses
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3874 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
284599bb38
commit
b35ec4b31f
@ -681,18 +681,13 @@ void Kart::handleZipper()
|
||||
// Ignore a zipper that's activated while braking
|
||||
if(m_controls.m_brake) return;
|
||||
m_zipper_time_left = stk_config->m_zipper_time;
|
||||
|
||||
btVector3 v = m_body->getLinearVelocity();
|
||||
float current_speed = v.length();
|
||||
float speed = std::min(current_speed+stk_config->m_zipper_speed_gain,
|
||||
getMaxSpeedOnTerrain());
|
||||
// If the speed is too low, very minor components of the velocity vector
|
||||
// can become too big. E.g. each kart has a z component (to offset gravity
|
||||
// I assume, around 0.16) --> if the karts are (nearly) at standstill,
|
||||
// the z component is exaggerated, resulting in a jump. Even if Z
|
||||
// is set to 0, minor left/right movements are then too strong.
|
||||
// Therefore a zipper only adds the speed if the speed is at least 1
|
||||
// (experimentally found valud). It also avoids NAN problems (if v=0).
|
||||
if(current_speed>1.0f) m_body->setLinearVelocity(v*(speed/current_speed));
|
||||
|
||||
m_vehicle->activateZipper(speed);
|
||||
} // handleZipper
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1067,6 +1062,8 @@ void Kart::endRescue()
|
||||
m_body->setLinearVelocity (btVector3(0.0f,0.0f,0.0f));
|
||||
m_body->setAngularVelocity(btVector3(0.0f,0.0f,0.0f));
|
||||
|
||||
m_vehicle->deactivateZipper();
|
||||
|
||||
// let the mode decide where to put the kart
|
||||
RaceManager::getWorld()->moveKartAfterRescue(this, m_body);
|
||||
|
||||
|
@ -32,6 +32,9 @@ btKart::btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
|
||||
: btRaycastVehicle(tuning, chassis, raycaster)
|
||||
{
|
||||
m_track_connect_accel = track_connect_accel;
|
||||
|
||||
m_zipper_active = false;
|
||||
m_zipper_velocity = btScalar(0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -414,42 +417,47 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
|
||||
btScalar rollingFriction = 0.f;
|
||||
|
||||
if (groundObject)
|
||||
{
|
||||
if (wheelInfo.m_engineForce != 0.f)
|
||||
{
|
||||
rollingFriction = wheelInfo.m_engineForce* timeStep;
|
||||
} else
|
||||
{
|
||||
btScalar defaultRollingFrictionImpulse = 0.f;
|
||||
btScalar maxImpulse = wheelInfo.m_brake ? wheelInfo.m_brake : defaultRollingFrictionImpulse;
|
||||
btWheelContactPoint contactPt(m_chassisBody,groundObject,wheelInfo.m_raycastInfo.m_contactPointWS,m_forwardWS[wheel],maxImpulse);
|
||||
rollingFriction = calcRollingFriction(contactPt);
|
||||
// This is a work around for the problem that a kart shakes
|
||||
// if it is braking: we get a minor impulse forward, which
|
||||
// bullet then tries to offset by applying a backward
|
||||
// impulse - which is a bit too big, causing a impulse
|
||||
// backwards, ... till the kart is shaking backwards and
|
||||
// forwards
|
||||
if(wheelInfo.m_brake && fabsf(rollingFriction)<10)
|
||||
rollingFriction=0;
|
||||
}
|
||||
}
|
||||
|
||||
//switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
|
||||
|
||||
|
||||
|
||||
|
||||
m_forwardImpulse[wheel] = btScalar(0.);
|
||||
m_wheelInfo[wheel].m_skidInfo= btScalar(1.);
|
||||
|
||||
if (groundObject)
|
||||
{
|
||||
m_forwardImpulse[wheel] = rollingFriction;//wheelInfo.m_engineForce* timeStep;
|
||||
}
|
||||
if (m_zipper_active)
|
||||
{
|
||||
if (wheel==2 || wheel==3)
|
||||
{
|
||||
m_forwardImpulse[wheel] = 0.5*(m_zipper_velocity - getRigidBody()->getLinearVelocity().length()) / m_chassisBody->getInvMass();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (wheelInfo.m_engineForce != 0.f)
|
||||
{
|
||||
rollingFriction = wheelInfo.m_engineForce* timeStep;
|
||||
} else
|
||||
{
|
||||
//switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
|
||||
btScalar defaultRollingFrictionImpulse = 0.f;
|
||||
btScalar maxImpulse = wheelInfo.m_brake ? wheelInfo.m_brake : defaultRollingFrictionImpulse;
|
||||
btWheelContactPoint contactPt(m_chassisBody,groundObject,wheelInfo.m_raycastInfo.m_contactPointWS,m_forwardWS[wheel],maxImpulse);
|
||||
rollingFriction = calcRollingFriction(contactPt);
|
||||
// This is a work around for the problem that a kart shakes
|
||||
// if it is braking: we get a minor impulse forward, which
|
||||
// bullet then tries to offset by applying a backward
|
||||
// impulse - which is a bit too big, causing a impulse
|
||||
// backwards, ... till the kart is shaking backwards and
|
||||
// forwards
|
||||
if(wheelInfo.m_brake && fabsf(rollingFriction)<10)
|
||||
rollingFriction=0;
|
||||
}
|
||||
|
||||
m_forwardImpulse[wheel] = rollingFriction;//wheelInfo.m_engineForce* timeStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_zipper_active = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,6 +24,8 @@ class btKart : public btRaycastVehicle
|
||||
void defaultInit(const btVehicleTuning& tuning);
|
||||
btScalar m_track_connect_accel;
|
||||
btScalar m_skidding_factor;
|
||||
bool m_zipper_active;
|
||||
btScalar m_zipper_velocity;
|
||||
public:
|
||||
btKart(const btVehicleTuning& tuning,btRigidBody* chassis,
|
||||
btVehicleRaycaster* raycaster, float track_connect_accel );
|
||||
@ -36,6 +38,8 @@ public:
|
||||
const btVector3& hitPoint,
|
||||
const btVector3& hitNormal,btScalar depth);
|
||||
void setPitchControl(btScalar pitch) { m_pitchControl = pitch; }
|
||||
void activateZipper(btScalar vel) { m_zipper_active = true; m_zipper_velocity = vel; }
|
||||
void deactivateZipper() { m_zipper_active = false; }
|
||||
void updateSuspension(btScalar deltaTime);
|
||||
virtual void updateFriction(btScalar timeStep);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user