Made restitution configurable (depending on speed of kart).
This commit is contained in:
parent
fcc1ab3abe
commit
53d2bc3b8e
@ -438,6 +438,11 @@
|
|||||||
period, which results in less abrupt changes. If set to 0,
|
period, which results in less abrupt changes. If set to 0,
|
||||||
the impulse is only applied once.
|
the impulse is only applied once.
|
||||||
resitution: restitution value to be used for the kart rigid bodies.
|
resitution: restitution value to be used for the kart rigid bodies.
|
||||||
|
The restitution used depends on the speed to avoid physics issues
|
||||||
|
(a collision with high speed and high restitution will push the
|
||||||
|
kart high up into the air). The values specified are
|
||||||
|
speed:restitution pairs, the actual restitution will be
|
||||||
|
interpolated based on the points specified here.
|
||||||
bevel-factor: for each point of the chassis collision box one
|
bevel-factor: for each point of the chassis collision box one
|
||||||
additional point is added, resulting in a bevelled box shape.
|
additional point is added, resulting in a bevelled box shape.
|
||||||
The original Z coordinate of the chassis is multiplied by
|
The original Z coordinate of the chassis is multiplied by
|
||||||
@ -457,7 +462,7 @@
|
|||||||
behaviour of the karts. -->
|
behaviour of the karts. -->
|
||||||
<collision impulse-type="normal"
|
<collision impulse-type="normal"
|
||||||
impulse="3000" impulse-time="0.1" terrain-impulse="160"
|
impulse="3000" impulse-time="0.1" terrain-impulse="160"
|
||||||
restitution="1.0" bevel-factor="0.5 0.0 0.3"
|
restitution="0:1.0 5:1.0 20:0.2" bevel-factor="0.5 0.0 0.3"
|
||||||
physical-wheel-position="0" />
|
physical-wheel-position="0" />
|
||||||
|
|
||||||
<!-- Skidding: increase: multiplicative increase of skidding factor in each frame.
|
<!-- Skidding: increase: multiplicative increase of skidding factor in each frame.
|
||||||
|
15
src/karts/kart.cpp
Executable file → Normal file
15
src/karts/kart.cpp
Executable file → Normal file
@ -721,7 +721,7 @@ void Kart::createPhysics()
|
|||||||
btTransform trans;
|
btTransform trans;
|
||||||
trans.setIdentity();
|
trans.setIdentity();
|
||||||
createBody(mass, trans, &m_kart_chassis,
|
createBody(mass, trans, &m_kart_chassis,
|
||||||
m_kart_properties->getRestitution());
|
m_kart_properties->getRestitution(0.0f));
|
||||||
std::vector<float> ang_fact = m_kart_properties->getStabilityAngularFactor();
|
std::vector<float> ang_fact = m_kart_properties->getStabilityAngularFactor();
|
||||||
// The angular factor (with X and Z values <1) helps to keep the kart
|
// The angular factor (with X and Z values <1) helps to keep the kart
|
||||||
// upright, especially in case of a collision.
|
// upright, especially in case of a collision.
|
||||||
@ -1266,12 +1266,13 @@ void Kart::eliminate()
|
|||||||
*/
|
*/
|
||||||
void Kart::update(int ticks)
|
void Kart::update(int ticks)
|
||||||
{
|
{
|
||||||
if(m_speed < 5.0f)
|
// Make the restitution depend on speed: this avoids collision issues,
|
||||||
m_body->setRestitution(1.0f);
|
// otherwise a collision with high speed can see a kart being push
|
||||||
else if(m_speed<20.0f)
|
// high up in the air (and out of control). So for higher speed we
|
||||||
m_body->setRestitution(1.0f-(m_speed-5.0f)/15.0f);
|
// reduce the restitution, meaning the karts will get less of a push
|
||||||
else
|
// based on the collision speed.
|
||||||
m_body->setRestitution(0.0f);
|
m_body->setRestitution(m_kart_properties->getRestitution(fabsf(m_speed)));
|
||||||
|
|
||||||
// Reset any instand speed increase in the bullet kart
|
// Reset any instand speed increase in the bullet kart
|
||||||
m_vehicle->setMinSpeed(0);
|
m_vehicle->setMinSpeed(0);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ KartProperties::KartProperties(const std::string &filename)
|
|||||||
// Set all other values to undefined, so that it can later be tested
|
// Set all other values to undefined, so that it can later be tested
|
||||||
// if everything is defined properly.
|
// if everything is defined properly.
|
||||||
m_wheel_base = m_friction_slip = m_collision_terrain_impulse =
|
m_wheel_base = m_friction_slip = m_collision_terrain_impulse =
|
||||||
m_collision_impulse = m_restitution = m_collision_impulse_time =
|
m_collision_impulse = m_collision_impulse_time =
|
||||||
m_max_lean = m_lean_speed = m_physical_wheel_position = UNDEFINED;
|
m_max_lean = m_lean_speed = m_physical_wheel_position = UNDEFINED;
|
||||||
|
|
||||||
m_terrain_impulse_type = IMPULSE_NONE;
|
m_terrain_impulse_type = IMPULSE_NONE;
|
||||||
@ -499,7 +499,7 @@ void KartProperties::getAllData(const XMLNode * root)
|
|||||||
void KartProperties::checkAllSet(const std::string &filename)
|
void KartProperties::checkAllSet(const std::string &filename)
|
||||||
{
|
{
|
||||||
#define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \
|
#define CHECK_NEG( a,strA) if(a<=UNDEFINED) { \
|
||||||
Log::fatal("[KartProperties]", \
|
Log::fatal("KartProperties", \
|
||||||
"Missing default value for '%s' in '%s'.", \
|
"Missing default value for '%s' in '%s'.", \
|
||||||
strA,filename.c_str()); \
|
strA,filename.c_str()); \
|
||||||
}
|
}
|
||||||
@ -508,9 +508,11 @@ void KartProperties::checkAllSet(const std::string &filename)
|
|||||||
CHECK_NEG(m_collision_terrain_impulse, "collision terrain-impulse" );
|
CHECK_NEG(m_collision_terrain_impulse, "collision terrain-impulse" );
|
||||||
CHECK_NEG(m_collision_impulse, "collision impulse" );
|
CHECK_NEG(m_collision_impulse, "collision impulse" );
|
||||||
CHECK_NEG(m_collision_impulse_time, "collision impulse-time" );
|
CHECK_NEG(m_collision_impulse_time, "collision impulse-time" );
|
||||||
CHECK_NEG(m_restitution, "collision restitution" );
|
|
||||||
CHECK_NEG(m_physical_wheel_position, "collision physical-wheel-position");
|
CHECK_NEG(m_physical_wheel_position, "collision physical-wheel-position");
|
||||||
|
|
||||||
|
if(m_restitution.size()<1)
|
||||||
|
Log::fatal("KartProperties", "Missing restitution value.");
|
||||||
|
|
||||||
for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++)
|
for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++)
|
||||||
m_ai_properties[i]->checkAllSet(filename);
|
m_ai_properties[i]->checkAllSet(filename);
|
||||||
} // checkAllSet
|
} // checkAllSet
|
||||||
|
@ -201,9 +201,8 @@ private:
|
|||||||
/** How long the collision impulse should be applied. */
|
/** How long the collision impulse should be applied. */
|
||||||
float m_collision_impulse_time;
|
float m_collision_impulse_time;
|
||||||
|
|
||||||
/** The restitution factor to be used in collsions for this kart. */
|
/** Restitution depending on speed. */
|
||||||
float m_restitution;
|
InterpolationArray m_restitution;
|
||||||
|
|
||||||
|
|
||||||
void load (const std::string &filename,
|
void load (const std::string &filename,
|
||||||
const std::string &node);
|
const std::string &node);
|
||||||
@ -340,7 +339,7 @@ public:
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the restitution factor for this kart. */
|
/** Returns the restitution factor for this kart. */
|
||||||
float getRestitution () const { return m_restitution; }
|
float getRestitution(float speed) const { return m_restitution.get(speed);}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns a pointer to the AI properties. */
|
/** Returns a pointer to the AI properties. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user