Added code for skidding (currently disabled, so no visible change).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10361 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1d15cb7ba0
commit
964d132364
@ -160,9 +160,13 @@
|
||||
decrease: multiplicative decrease of skidding factor in each frame.
|
||||
max: maximum skidding factor = maximum increase of steering angle.
|
||||
time-till-max: Time till maximum skidding is reached.
|
||||
visual: Additional graphical rotation of kart. -->
|
||||
visual: Additional graphical rotation of kart.
|
||||
angular-velocity: Angular velocity to be used for the kart when skidding.
|
||||
bonus-time: How long a kart needs to skid in order to get a bonus. -->
|
||||
<!-- Note: for now skidding is disabled, set angular-velocity to 2 to test it -->
|
||||
<skid increase="1.05" decrease="0.95" max="2.5" time-till-max="0.4"
|
||||
visual="0.16"/>
|
||||
visual="0.0"
|
||||
angular-velocity="0" bonus-time="5"/>
|
||||
|
||||
<!-- Slipstream: length: How far behind a kart slipstream works
|
||||
collect-time: How many seconds of sstream give maximum benefit
|
||||
|
@ -1779,6 +1779,15 @@ void Kart::updatePhysics(float dt)
|
||||
m_vehicle->setSteeringValue(steering, 0);
|
||||
m_vehicle->setSteeringValue(steering, 1);
|
||||
|
||||
// Handle skidding
|
||||
float ang_vel = 0;
|
||||
if(m_controls.m_drift)
|
||||
if(m_controls.m_steer>0)
|
||||
ang_vel = m_kart_properties->getSkidAngularVelocity();
|
||||
else if (m_controls.m_steer<0)
|
||||
ang_vel = -m_kart_properties->getSkidAngularVelocity();
|
||||
m_vehicle->setSkidAngularVelocity(ang_vel);
|
||||
|
||||
// Only compute the current speed if this is not the client. On a client the
|
||||
// speed is actually received from the server.
|
||||
if(network_manager->getMode()!=NetworkManager::NW_CLIENT)
|
||||
|
@ -84,6 +84,7 @@ KartProperties::KartProperties(const std::string &filename)
|
||||
m_zipper_max_speed_increase = m_zipper_fade_out_time =
|
||||
m_time_till_max_skid =
|
||||
m_skid_decrease = m_skid_increase = m_skid_visual = m_skid_max =
|
||||
m_skid_angular_velocity = m_skid_bonus_time =
|
||||
m_slipstream_length = m_slipstream_collect_time =
|
||||
m_slipstream_use_time = m_slipstream_add_power =
|
||||
m_slipstream_min_speed = m_slipstream_max_speed_increase =
|
||||
@ -288,12 +289,14 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
}
|
||||
if(const XMLNode *skid_node = root->getNode("skid"))
|
||||
{
|
||||
skid_node->get("increase", &m_skid_increase );
|
||||
skid_node->get("decrease", &m_skid_decrease );
|
||||
skid_node->get("max", &m_skid_max );
|
||||
skid_node->get("time-till-max", &m_time_till_max_skid);
|
||||
skid_node->get("visual", &m_skid_visual );
|
||||
skid_node->get("enable", &m_has_skidmarks );
|
||||
skid_node->get("increase", &m_skid_increase );
|
||||
skid_node->get("decrease", &m_skid_decrease );
|
||||
skid_node->get("max", &m_skid_max );
|
||||
skid_node->get("time-till-max", &m_time_till_max_skid );
|
||||
skid_node->get("visual", &m_skid_visual );
|
||||
skid_node->get("enable", &m_has_skidmarks );
|
||||
skid_node->get("bonus-time", &m_skid_bonus_time );
|
||||
skid_node->get("angular-velocity", &m_skid_angular_velocity);
|
||||
}
|
||||
|
||||
if(const XMLNode *slipstream_node = root->getNode("slipstream"))
|
||||
@ -608,6 +611,8 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_skid_increase, "skid increase" );
|
||||
CHECK_NEG(m_skid_max, "skid max" );
|
||||
CHECK_NEG(m_skid_visual, "skid visual" );
|
||||
CHECK_NEG(m_skid_angular_velocity, "skid angular-velocity" );
|
||||
CHECK_NEG(m_skid_bonus_time, "skid bonus-time" );
|
||||
CHECK_NEG(m_slipstream_length, "slipstream length" );
|
||||
CHECK_NEG(m_slipstream_collect_time, "slipstream collect-time" );
|
||||
CHECK_NEG(m_slipstream_use_time, "slipstream use-time" );
|
||||
|
@ -288,6 +288,13 @@ private:
|
||||
float m_time_till_max_skid;
|
||||
/** Kart leaves skid marks. */
|
||||
bool m_has_skidmarks;
|
||||
|
||||
/** Angular velocity to be applied when skidding. */
|
||||
float m_skid_angular_velocity;
|
||||
|
||||
/** Time of skidding before you get a bonus boost. */
|
||||
float m_skid_bonus_time;
|
||||
|
||||
/** Make the AI to steer at slightly different points to make it less
|
||||
* likely that the AI creates 'trains' - the kart behind getting
|
||||
* slipstream. The variation should be a value between 0 (no variation,
|
||||
@ -620,6 +627,12 @@ public:
|
||||
/** Returns if the kart leaves skidmarks or not. */
|
||||
bool hasSkidmarks () const {return m_has_skidmarks; }
|
||||
|
||||
/** Returns the angular velocity to be applied when skidding. */
|
||||
float getSkidAngularVelocity() const { return m_skid_angular_velocity; }
|
||||
|
||||
/** Returns the time of skidding before you get a bonus boost. */
|
||||
float getSkidBonusTime() const { return m_skid_bonus_time; }
|
||||
|
||||
/** Returns ratio of current speed to max speed at which the gear will
|
||||
* change (for our simualated gears = simple change of engine power). */
|
||||
const std::vector<float>&
|
||||
|
@ -107,6 +107,8 @@ void btKart::reset()
|
||||
}
|
||||
m_zipper_active = false;
|
||||
m_zipper_velocity = btScalar(0);
|
||||
m_skid_angular_velocity = 0;
|
||||
m_is_skidding = false;
|
||||
m_allow_sliding = false;
|
||||
m_currentVehicleSpeedKmHour = btScalar(0.);
|
||||
m_num_wheels_on_ground = 0;
|
||||
@ -595,20 +597,12 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
m_forwardImpulse.resize(numWheel);
|
||||
m_sideImpulse.resize(numWheel);
|
||||
|
||||
int numWheelsOnGround = 0;
|
||||
|
||||
|
||||
//collapse all those loops into one!
|
||||
for (int i=0;i<getNumWheels();i++)
|
||||
{
|
||||
btWheelInfo& wheelInfo = m_wheelInfo[i];
|
||||
btRigidBody* groundObject =
|
||||
(btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
|
||||
if (groundObject)
|
||||
numWheelsOnGround++;
|
||||
m_sideImpulse[i] = btScalar(0.);
|
||||
m_sideImpulse[i] = btScalar(0.);
|
||||
m_forwardImpulse[i] = btScalar(0.);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -729,7 +723,35 @@ void btKart::updateFriction(btScalar timeStep)
|
||||
|
||||
m_zipper_active = false;
|
||||
m_zipper_velocity = 0;
|
||||
if (sliding)
|
||||
|
||||
// The kart just stopped skidding. Adjust the velocity so that
|
||||
// it points in the right direction.
|
||||
// FIXME: this is not good enough, we need some smooth interpolation here.
|
||||
if(m_is_skidding && m_skid_angular_velocity == 0)
|
||||
{
|
||||
btVector3 v = m_chassisBody->getLinearVelocity();
|
||||
v.setZ(sqrt(v.getX()*v.getX()+v.getZ()*v.getZ()));
|
||||
v.setX(0);
|
||||
btVector3 v_new = m_chassisBody->getWorldTransform().getBasis()*v;
|
||||
m_chassisBody->setLinearVelocity(v_new);
|
||||
m_is_skidding = false;
|
||||
}
|
||||
|
||||
if(m_skid_angular_velocity!=0)
|
||||
{
|
||||
m_is_skidding = true;
|
||||
// Skidding is implemented by not having any forward impulse,
|
||||
// but only add a side impulse
|
||||
for(unsigned int i=0; i<4; i++)
|
||||
{
|
||||
m_forwardImpulse[i] = 0;
|
||||
m_sideImpulse[i] = 0;
|
||||
}
|
||||
btVector3 av = m_chassisBody->getAngularVelocity();
|
||||
av.setY(m_skid_angular_velocity);
|
||||
m_chassisBody->setAngularVelocity(av);
|
||||
}
|
||||
else if (sliding)
|
||||
{
|
||||
for (int wheel = 0; wheel < getNumWheels(); wheel++)
|
||||
{
|
||||
|
@ -66,8 +66,22 @@ protected:
|
||||
btScalar m_damping;
|
||||
btVehicleRaycaster *m_vehicleRaycaster;
|
||||
btScalar m_currentVehicleSpeedKmHour;
|
||||
/** True if a zipper is active for that kart. */
|
||||
bool m_zipper_active;
|
||||
|
||||
/** The zipper velocity (i.e. the velocity the kart should reach in
|
||||
* the first frame that the zipper is active). */
|
||||
btScalar m_zipper_velocity;
|
||||
|
||||
/** The angular velocity to be applied when the kart skids.
|
||||
* 0 means no skidding. */
|
||||
btScalar m_skid_angular_velocity;
|
||||
|
||||
/** True if the kart is currently skidding. This is used to detect
|
||||
* the end of skidding (i.e. m_skid_angular_velocity=0 and
|
||||
* m_is_skidding=true), and triggers adjusting of the velocity
|
||||
* direction. */
|
||||
bool m_is_skidding;
|
||||
|
||||
/** Sliding (skidding) will only be permited when this is true. Also check
|
||||
* the friction parameter in the wheels since friction directly affects
|
||||
@ -236,6 +250,10 @@ public:
|
||||
bool projectVehicleToSurface(const btVector3& ray,
|
||||
bool translate_vehicle);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the angular velocity to be used when skidding
|
||||
* (0 means no skidding). */
|
||||
void setSkidAngularVelocity(float v) {m_skid_angular_velocity = v; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of wheels on the ground. */
|
||||
unsigned int getNumWheelsOnGround() const {return m_num_wheels_on_ground;}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user