Fixed missing startup boost, improved maths to only use

velocity in the current plane for boosting.
This commit is contained in:
hiker 2018-02-09 09:15:23 +11:00
parent 3788a3d90d
commit 6c0f97261a
2 changed files with 18 additions and 10 deletions

View File

@ -1011,17 +1011,22 @@ void btKart::adjustSpeed(btScalar min_speed, btScalar max_speed)
{
const btVector3 &velocity = m_chassisBody->getLinearVelocity();
float speed = velocity.length();
if (speed < min_speed && min_speed > 0)
{
if (speed == 0)
if (speed > 0)
{
m_chassisBody->setLinearVelocity(btVector3(0, 0, min_speed));
}
else
{
const float velocity_ratio = min_speed / speed;
m_chassisBody->setLinearVelocity(velocity * velocity_ratio);
// The speedup is only for the direction of the normal.
const btVector3 &normal = m_kart->getNormal();
btVector3 upright_component = normal * normal.dot(velocity);
// Subtract the upright velocity component,
btVector3 v = velocity - upright_component;
const float velocity_ratio = min_speed / v.length();
// Scale the velocity in the plane, then add the upright component
// of the velocity back in.
m_chassisBody->setLinearVelocity( v*velocity_ratio
+ upright_component );
}
}
else if (speed >0 && max_speed >= 0 && speed > max_speed)

View File

@ -292,10 +292,13 @@ public:
// ------------------------------------------------------------------------
/** Resets the maximum so any new maximum value from the application will
* be accepted. */
virtual void resetMaxSpeed() { m_max_speed = -1.0f; }
virtual void resetMaxSpeed() { m_max_speed = -1.0f; m_min_speed = 0.0f; }
// ------------------------------------------------------------------------
/** Sets the minimum speed for this kart. */
void setMinSpeed(float s) { m_min_speed = s; }
void setMinSpeed(float s)
{
if(s > m_min_speed) m_min_speed = s;
}
// ------------------------------------------------------------------------
/** Returns the minimum speed for this kart. */
btScalar getMinSpeed() const { return m_min_speed; }