Added options to apply an impulse for a certain amount of time. This
way pushing two karts away from each other is less abrupt. This is now enabled, feedback (or tweaks) welcome. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10439 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
683b0e1903
commit
c3a057f206
@ -280,6 +280,9 @@
|
||||
<!-- collision
|
||||
impulse: an additional impulse to be applied in a non-frontal
|
||||
collision to push two karts away from each other.
|
||||
impulse-time: The impulse will be applied over a certain time
|
||||
period, which results in less abrupt changes. If set to 0,
|
||||
the impulse is only applied once.
|
||||
resitution: restitution value to be used for the kart rigid bodies.
|
||||
side-impulse: an additional (artificial) impulse that
|
||||
pushes the slower kart out of the way of the faster karts (i.e.
|
||||
@ -289,7 +292,8 @@
|
||||
the orientation - if a kart is pushed in the direction it is
|
||||
driving, it will be more (no friction from tires), while when
|
||||
pushed to the side, hardly anything happens. -->
|
||||
<collision impulse="1500" restitution="0.5" side-impulse="4500"/>
|
||||
<collision impulse="300" impulse-time="0.2" side-impulse="900"
|
||||
restitution="0.5"/>
|
||||
|
||||
<!-- Kart-specific plunger and rubber band handling: max-length is
|
||||
the maximum length of rubber band before it snaps. force is
|
||||
|
@ -74,6 +74,7 @@ KartProperties::KartProperties(const std::string &filename)
|
||||
m_max_speed_reverse_ratio =
|
||||
m_rescue_vert_offset = m_upright_tolerance =
|
||||
m_collision_side_impulse = m_collision_impulse = m_restitution =
|
||||
m_collision_impulse_time =
|
||||
m_upright_max_force = m_suspension_travel_cm =
|
||||
m_track_connection_accel =
|
||||
m_rubber_band_max_length = m_rubber_band_force =
|
||||
@ -428,6 +429,7 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
if(const XMLNode *collision_node = root->getNode("collision"))
|
||||
{
|
||||
collision_node->get("impulse", &m_collision_impulse );
|
||||
collision_node->get("impulse-time", &m_collision_impulse_time);
|
||||
collision_node->get("side-impulse", &m_collision_side_impulse);
|
||||
collision_node->get("restitution", &m_restitution );
|
||||
}
|
||||
@ -595,6 +597,7 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_suspension_travel_cm, "suspension travel-cm" );
|
||||
CHECK_NEG(m_max_suspension_force, "suspension max-force" );
|
||||
CHECK_NEG(m_collision_impulse, "collision impulse" );
|
||||
CHECK_NEG(m_collision_impulse_time, "collision impulse-time" );
|
||||
CHECK_NEG(m_restitution, "collision restitution" );
|
||||
CHECK_NEG(m_collision_side_impulse, "collision side-impulse" );
|
||||
CHECK_NEG(m_upright_tolerance, "upright tolerance" );
|
||||
|
@ -257,6 +257,9 @@ private:
|
||||
* side-side collision away from each other. */
|
||||
float m_collision_impulse;
|
||||
|
||||
/** How long the collision impulse should be applied. */
|
||||
float m_collision_impulse_time;
|
||||
|
||||
/** The restitution factor to be used in collsions for this kart. */
|
||||
float m_restitution;
|
||||
|
||||
@ -511,6 +514,9 @@ public:
|
||||
* to another kart in case of a non-frontal collision. */
|
||||
float getCollisionImpulse () const {return m_collision_impulse;}
|
||||
|
||||
/** Returns how long the collision impulse should be applied. */
|
||||
float getCollisionImpulseTime() const { return m_collision_impulse_time;}
|
||||
|
||||
/** Returns the restitution factor for this kart. */
|
||||
float getRestitution () const { return m_restitution; }
|
||||
|
||||
|
@ -117,6 +117,8 @@ void btKart::reset()
|
||||
m_is_skidding = false;
|
||||
m_allow_sliding = false;
|
||||
m_num_wheels_on_ground = 0;
|
||||
m_additional_impulse = btVector3(0,0,0);
|
||||
m_time_additional_impulse = 0;
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -414,6 +416,12 @@ void btKart::updateVehicle( btScalar step )
|
||||
* btVector3(0, f, 0);
|
||||
|
||||
m_chassisBody->applyCentralImpulse(downwards_impulse);
|
||||
|
||||
if(m_time_additional_impulse>0)
|
||||
{
|
||||
m_time_additional_impulse -= step;
|
||||
m_chassisBody->applyCentralImpulse(m_additional_impulse);
|
||||
}
|
||||
} // updateVehicle
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -91,6 +91,13 @@ private:
|
||||
* skidding.
|
||||
*/
|
||||
bool m_allow_sliding;
|
||||
|
||||
/** An additional impulse that is applied for a certain amount of time. */
|
||||
btVector3 m_additional_impulse;
|
||||
|
||||
/** The time the additional impulse should be applied. */
|
||||
float m_time_additional_impulse;
|
||||
|
||||
|
||||
btRigidBody *m_chassisBody;
|
||||
|
||||
@ -199,6 +206,20 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of wheels on the ground. */
|
||||
unsigned int getNumWheelsOnGround() const {return m_num_wheels_on_ground;}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets an impulse that is applied for a certain amount of time.
|
||||
* \param t Time for the impulse to be active.
|
||||
* \param imp The impulse to apply. */
|
||||
void setTimedImpulse(float t, const btVector3 &imp)
|
||||
{
|
||||
// Only add impulse if no other impulse is active.
|
||||
if(m_time_additional_impulse>0) return;
|
||||
m_additional_impulse = imp;
|
||||
m_time_additional_impulse = t;
|
||||
} // setTimedImpulse
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the time an additional impulse is activated. */
|
||||
float getImpulseTime() const { return m_time_additional_impulse; }
|
||||
}; // class btKart
|
||||
|
||||
#endif //BT_RAYCASTVEHICLE_H
|
||||
#endif //BT_KART_HPP
|
||||
|
@ -351,7 +351,12 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
|
||||
impulse = Vec3(-dir.getZ(), 0, dir.getX());
|
||||
impulse.normalize();
|
||||
impulse *= faster_kart->getKartProperties()->getCollisionImpulse();
|
||||
slower_kart->getBody()->applyCentralImpulse(impulse);
|
||||
float t =
|
||||
faster_kart->getKartProperties()->getCollisionImpulseTime();
|
||||
if(t>0)
|
||||
slower_kart->getVehicle()->setTimedImpulse(t, impulse);
|
||||
else
|
||||
slower_kart->getBody()->applyCentralImpulse(impulse);
|
||||
slower_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
|
||||
// Apply some impulse to the slower kart as well?
|
||||
}
|
||||
@ -367,7 +372,12 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
|
||||
impulse = Vec3( dir.getZ(), 0, -dir.getX());
|
||||
impulse.normalize();
|
||||
impulse *= slower_kart->getKartProperties()->getCollisionImpulse();
|
||||
faster_kart->getBody()->applyCentralImpulse(impulse);
|
||||
float t =
|
||||
faster_kart->getKartProperties()->getCollisionImpulseTime();
|
||||
if(t>0)
|
||||
faster_kart->getVehicle()->setTimedImpulse(t, impulse);
|
||||
else
|
||||
faster_kart->getBody()->applyCentralImpulse(impulse);
|
||||
faster_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
|
||||
|
||||
// Then the slower kart
|
||||
@ -379,7 +389,11 @@ void Physics::KartKartCollision(Kart *kart_a, const Vec3 &contact_point_a,
|
||||
|
||||
impulse.normalize();
|
||||
impulse *= faster_kart->getKartProperties()->getCollisionImpulse();
|
||||
slower_kart->getBody()->applyCentralImpulse(impulse);
|
||||
t = faster_kart->getKartProperties()->getCollisionImpulseTime();
|
||||
if(t>0)
|
||||
slower_kart->getVehicle()->setTimedImpulse(t, impulse);
|
||||
else
|
||||
slower_kart->getBody()->applyCentralImpulse(impulse);
|
||||
slower_kart->getBody()->setAngularVelocity(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user