Replaced old zipper handling in physics with minSpeed setting.
This commit is contained in:
parent
1c2fdc1c14
commit
d5938a2447
@ -1209,7 +1209,7 @@ void Kart::eliminate()
|
||||
void Kart::update(float dt)
|
||||
{
|
||||
// Reset any instand speed increase in the bullet kart
|
||||
m_vehicle->resetInstantSpeed();
|
||||
m_vehicle->setMinSpeed(0);
|
||||
|
||||
// update star effect (call will do nothing if stars are not activated)
|
||||
m_stars_effect->update(dt);
|
||||
|
@ -74,7 +74,7 @@ BareNetworkString* KartRewinder::saveState() const
|
||||
buffer->add(body->getLinearVelocity());
|
||||
buffer->add(body->getAngularVelocity());
|
||||
buffer->addUInt8(m_has_started); // necessary for startup speed boost
|
||||
buffer->addFloat(m_vehicle->getInstantSpeedIncrease());
|
||||
buffer->addFloat(m_vehicle->getMinSpeed());
|
||||
|
||||
// 2) Steering and other player controls
|
||||
// -------------------------------------
|
||||
@ -120,7 +120,7 @@ void KartRewinder::rewindToState(BareNetworkString *buffer)
|
||||
// before Moveable::update() is called (which updates the transform)
|
||||
setTrans(t);
|
||||
m_has_started = buffer->getUInt8()!=0; // necessary for startup speed boost
|
||||
m_vehicle->instantSpeedIncreaseTo(buffer->getFloat());
|
||||
m_vehicle->setMinSpeed(buffer->getFloat());
|
||||
|
||||
// 2) Steering and other controls
|
||||
// ------------------------------
|
||||
|
@ -118,7 +118,6 @@ void btKart::reset()
|
||||
updateWheelTransform(i, true);
|
||||
}
|
||||
m_visual_wheels_touch_ground = false;
|
||||
m_zipper_speed = btScalar(0);
|
||||
m_skid_angular_velocity = 0;
|
||||
m_is_skidding = false;
|
||||
m_allow_sliding = false;
|
||||
@ -773,51 +772,35 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
(btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
|
||||
if(!groundObject) continue;
|
||||
|
||||
if(m_zipper_speed > 0)
|
||||
{
|
||||
if (wheel==2 || wheel==3)
|
||||
{
|
||||
// The zipper velocity is the speed that should be
|
||||
// reached. So compute the impulse to accelerate the
|
||||
// kart up to that speed:
|
||||
m_forwardImpulse[wheel] =
|
||||
0.5f*(m_zipper_speed -
|
||||
getRigidBody()->getLinearVelocity().length())
|
||||
/ m_chassisBody->getInvMass();
|
||||
}
|
||||
btScalar rollingFriction = 0.f;
|
||||
|
||||
if (wheelInfo.m_engineForce != 0.f)
|
||||
{
|
||||
rollingFriction = wheelInfo.m_engineForce* timeStep;
|
||||
}
|
||||
else
|
||||
{
|
||||
btScalar rollingFriction = 0.f;
|
||||
|
||||
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. By only applying half of the impulse in case
|
||||
// of low friction this goes away.
|
||||
if(wheelInfo.m_brake && fabsf(rollingFriction)<10)
|
||||
rollingFriction*=0.5f;
|
||||
}
|
||||
|
||||
m_forwardImpulse[wheel] = rollingFriction;
|
||||
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. By only applying half of the impulse in case
|
||||
// of low friction this goes away.
|
||||
if (wheelInfo.m_brake && fabsf(rollingFriction) < 10)
|
||||
rollingFriction *= 0.5f;
|
||||
}
|
||||
|
||||
m_forwardImpulse[wheel] = rollingFriction;
|
||||
|
||||
if(m_time_additional_impulse>0)
|
||||
{
|
||||
sliding = true;
|
||||
@ -1017,21 +1000,6 @@ void btKart::setSliding(bool active)
|
||||
m_allow_sliding = active;
|
||||
} // setSliding
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Activates an additional speedup for the kart so that it reaches the
|
||||
* specified speed.
|
||||
* \param speed The speed to reach.
|
||||
*/
|
||||
void btKart::instantSpeedIncreaseTo(btScalar speed)
|
||||
{
|
||||
// Avoid that a speed 'increase' might cause a slowdown
|
||||
if (m_chassisBody->getLinearVelocity().length2() > speed*speed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_zipper_speed = speed;
|
||||
} // activateZipper
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Adjusts the velocity of this kart to be at least the specified minimum,
|
||||
* and less than or equal to the maximum. If necessary the kart will
|
||||
|
@ -69,10 +69,6 @@ private:
|
||||
btScalar m_damping;
|
||||
btVehicleRaycaster *m_vehicleRaycaster;
|
||||
|
||||
/** The zipper speed (i.e. the velocity the kart should reach in
|
||||
* the first frame that the zipper is active). */
|
||||
btScalar m_zipper_speed;
|
||||
|
||||
/** The angular velocity to be applied when the kart skids.
|
||||
* 0 means no skidding. */
|
||||
btScalar m_skid_angular_velocity;
|
||||
@ -282,9 +278,6 @@ public:
|
||||
m_time_additional_rotation = t;
|
||||
} // setTimedTorque
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current zipper speed. */
|
||||
float getInstantSpeedIncrease() const { return m_zipper_speed; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the maximum speed for this kart. */
|
||||
void setMaxSpeed(float new_max_speed)
|
||||
{
|
||||
@ -304,7 +297,8 @@ public:
|
||||
/** Sets the minimum speed for this kart. */
|
||||
void setMinSpeed(float s) { m_min_speed = s; }
|
||||
// ------------------------------------------------------------------------
|
||||
void resetInstantSpeed() { m_zipper_speed = 0; }
|
||||
/** Returns the minimum speed for this kart. */
|
||||
btScalar getMinSpeed() const { return m_min_speed; }
|
||||
}; // class btKart
|
||||
|
||||
#endif //BT_KART_HPP
|
||||
|
Loading…
x
Reference in New Issue
Block a user