Added some code to add a 'push to the side' when crashing into a kart.

This code is for now disabled in the stk_config.xml file, since it needs
changes to the physics to be better playable.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4422 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-01-10 12:16:32 +00:00
parent 2c60045223
commit 2f268dce77
5 changed files with 59 additions and 6 deletions

View File

@ -147,7 +147,15 @@ jump-velocity is the z-axis velocity set when a jump is initiated. This
will cause the kart to start rising, till it is pulled back by gravity.
A higher value means higher Z velocity, meaning the kart will rise faster
and higher, and will be in the air longer
collision-side-impulse is an additional (artificial) impulse that pushes
the slower kart out of the way of the faster karts (i.e. sideways to the
faster kart) when a collision happens. This is for now disables, since
it needs tuning and additionally has the problem that the amount of push
a hit kart receives depends on 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.
z-rescue-offset is the z-axis offset when kart is being put back on track
after being rescued, it's a fraction of kart height
@ -211,6 +219,7 @@ rubber-band-duration is the duration a rubber band acts.
suspension-rest="0.2"
suspension-travel-cm="19"
jump-velocity="3.0"
collision-side-impulse="0"
z-rescue-offset="0.0"
wheel-front-right="0.38 0.6 0"
wheel-front-left="-0.38 0.6 0"

View File

@ -62,7 +62,7 @@ KartProperties::KartProperties(const std::string &filename) : m_icon_material(0)
m_wheel_radius = m_chassis_linear_damping =
m_chassis_angular_damping = m_suspension_rest =
m_max_speed_reverse_ratio = m_jump_velocity =
m_z_rescue_offset = m_upright_tolerance =
m_z_rescue_offset = m_upright_tolerance = m_collision_side_impulse =
m_upright_max_force = m_suspension_travel_cm =
m_track_connection_accel = m_min_speed_turn = m_angle_at_min =
m_max_speed_turn = m_angle_at_max =
@ -314,6 +314,7 @@ void KartProperties::getAllData(const XMLNode * root)
root->get("suspension-rest", &m_suspension_rest);
root->get("suspension-travel-cm", &m_suspension_travel_cm);
root->get("jump-velocity", &m_jump_velocity);
root->get("collision-side-impulse", &m_collision_side_impulse);
root->get("z-rescue-offset", &m_z_rescue_offset);
//TODO: wheel front right and wheel front left is not loaded, yet is listed as an attribute in the xml file after wheel-radius
@ -432,6 +433,7 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
lisp->get("gravity-center-shift", m_gravity_center_shift );
lisp->get("suspension-rest", m_suspension_rest );
lisp->get("suspension-travel-cm", m_suspension_travel_cm );
lisp->get("collision-side-impulse", m_collision_side_impulse );
lisp->get("jump-velocity", m_jump_velocity );
lisp->get("z-rescue-offset", m_z_rescue_offset );
lisp->get("upright-tolerance", m_upright_tolerance );
@ -527,6 +529,7 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_max_speed_reverse_ratio, "max-speed-reverse-ratio" );
CHECK_NEG(m_suspension_rest, "suspension-rest" );
CHECK_NEG(m_suspension_travel_cm, "suspension-travel-cm" );
CHECK_NEG(m_collision_side_impulse, "collision-side-impulse" );
CHECK_NEG(m_jump_velocity, "jump-velocity" );
CHECK_NEG(m_z_rescue_offset, "z-rescue-offset" );
CHECK_NEG(m_upright_tolerance, "upright-tolerance" );

View File

@ -127,6 +127,9 @@ private:
* loses contact with the track. */
float m_suspension_rest;
float m_suspension_travel_cm;
/** An additional artifical side-impulse that pushes the slower kart
* out of the way of the faster kart in case of a collision. */
float m_collision_side_impulse;
float m_jump_velocity; // z velocity set when jumping
float m_z_rescue_offset; // z offset after rescue
float m_upright_tolerance;
@ -224,6 +227,9 @@ public:
float getSuspensionRest () const {return m_suspension_rest; }
float getSuspensionTravelCM () const {return m_suspension_travel_cm; }
float getJumpVelocity () const {return m_jump_velocity; }
/** Returns the (artificial) collision side impulse this kart will apply
* to a slower kart in case of a collision. */
float getCollisionSideImpulse () const {return m_collision_side_impulse; }
float getZRescueOffset () const {return m_z_rescue_offset; }
float getUprightTolerance () const {return m_upright_tolerance; }
float getUprightMaxForce () const {return m_upright_max_force; }

View File

@ -166,8 +166,8 @@ bool Physics::projectKartDownwards(const Kart *k)
//-----------------------------------------------------------------------------
/** Handles the special case of two karts colliding with each other, which means
* that bombs must be passed on. If both karts have a bomb, they'll explode
* immediately. This function is called from physics::update on the server
* (and if no networking is used), and from race_state on the client to replay
* immediately. This function is called from physics::update() on the server
* and if no networking is used, and from race_state on the client to replay
* what happened on the server.
* \param kartA First kart involved in the collision.
* \param kartB Second kart involved in the collision.
@ -205,10 +205,45 @@ void Physics::KartKartCollision(Kart *kartA, Kart *kartB)
}
else
{
// No bombs exchanged, no explosions, tell the other driver to move it!
kartA->playCustomSFX(SFXManager::CUSTOM_CRASH);
kartB->playCustomSFX(SFXManager::CUSTOM_CRASH);
}
// If bouncing crashes is enabled, add an additional force to the
// slower kart
Kart *faster_kart, *slower_kart;
if(kartA->getSpeed()>=kartB->getSpeed())
{
faster_kart = kartA;
slower_kart = kartB;
}
else
{
faster_kart = kartB;
slower_kart = kartA;
}
float side_impulse = faster_kart->getKartProperties()->getCollisionSideImpulse();
if(side_impulse>0)
{
Vec3 forwards_ws(0, 1, 0);
Vec3 forwards = faster_kart->getTrans()*forwards_ws;
core::line2df f(faster_kart->getXYZ().getX(),
faster_kart->getXYZ().getY(),
forwards.getX(), forwards.getY());
core::vector2df p(slower_kart->getXYZ().getX(),
slower_kart->getXYZ().getY());
float orientation=f.getPointOrientation(p);
// Now compute the vector to the side (right or left depending
// on where the kart was hit).
Vec3 side((orientation>=0) ? -1.0f : 1.0f, 0, 0);
float speed_frac = faster_kart->getSpeed()/faster_kart->getMaxSpeed();
Vec3 impulse =
faster_kart->getTrans().getRotation()*side*side_impulse*speed_frac;
printf("orientation is %f impulse is %f %f %f\n",
orientation, impulse.getX(),impulse.getY(),impulse.getZ());
slower_kart->getBody()->applyCentralImpulse(impulse);
}
} // KartKartCollision
//-----------------------------------------------------------------------------

View File

@ -40,7 +40,7 @@ private:
btDefaultMotionState *m_motion_state;
btCollisionShape *m_collision_shape;
public:
TriangleMesh() : m_mesh() {};
TriangleMesh() : m_mesh() {};
~TriangleMesh();
void addTriangle(const btVector3 &t1, const btVector3 &t2,
const btVector3 &t3, const Material* m);