Adjust wheel position in case of leaning: move the wheels on the side
that is higher in the air a bit further down so that they touch the ground. Fixed #2400.
This commit is contained in:
parent
1870691900
commit
94ad7ad676
@ -114,7 +114,8 @@ void GhostKart::update(float dt)
|
||||
Moveable::updateGraphics(dt, center_shift, btQuaternion(0, 0, 0, 1));
|
||||
Moveable::updatePosition();
|
||||
getKartModel()->update(dt, dt*(m_all_physic_info[idx].m_speed),
|
||||
m_all_physic_info[idx].m_steer, m_all_physic_info[idx].m_speed, idx);
|
||||
m_all_physic_info[idx].m_steer, m_all_physic_info[idx].m_speed,
|
||||
/*lean*/0.0f, idx);
|
||||
|
||||
getKartGFX()->setGFXFromReplay(m_all_replay_events[idx].m_nitro_usage,
|
||||
m_all_replay_events[idx].m_zipper_usage,
|
||||
|
@ -2745,12 +2745,12 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
|
||||
|
||||
// If the kart is leaning, part of the kart might end up 'in' the track.
|
||||
// To avoid this, raise the kart enough to offset the leaning.
|
||||
float lean_height = tan(fabsf(m_current_lean)) * getKartWidth()*0.5f;
|
||||
float lean_height = tan(m_current_lean) * getKartWidth()*0.5f;
|
||||
|
||||
Vec3 center_shift(0, 0, 0);
|
||||
|
||||
center_shift.setY(m_skidding->getGraphicalJumpOffset()
|
||||
+ lean_height
|
||||
+ fabsf(lean_height)
|
||||
+m_graphical_y_offset);
|
||||
center_shift = getTrans().getBasis() * center_shift;
|
||||
|
||||
@ -2760,7 +2760,7 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
|
||||
|
||||
// m_speed*dt is the distance the kart has moved, which determines
|
||||
// how much the wheels need to rotate.
|
||||
m_kart_model->update(dt, m_speed*dt, getSteerPercent(), m_speed);
|
||||
m_kart_model->update(dt, m_speed*dt, getSteerPercent(), m_speed, lean_height);
|
||||
|
||||
// Determine the shadow position from the terrain Y position. This
|
||||
// leaves the shadow on the ground even if the kart is jumping because
|
||||
|
@ -689,7 +689,7 @@ void KartModel::reset()
|
||||
m_wheel_node[i]->setRotation(rotation);
|
||||
}
|
||||
}
|
||||
update(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
update(0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
// Stop any animations currently being played.
|
||||
setAnimation(KartModel::AF_DEFAULT);
|
||||
@ -833,10 +833,12 @@ void KartModel::setDefaultSuspension()
|
||||
* \param suspension Suspension height for all four wheels.
|
||||
* \param speed The speed of the kart in meters/sec, used for the
|
||||
* speed-weighted objects' animations
|
||||
* \param current_lean_angle How much the kart is leaning (positive meaning
|
||||
* left side down)
|
||||
* \param gt_replay_index The index to get replay data, used by ghost kart
|
||||
*/
|
||||
void KartModel::update(float dt, float distance, float steer, float speed,
|
||||
int gt_replay_index)
|
||||
float current_lean_angle, int gt_replay_index)
|
||||
{
|
||||
core::vector3df wheel_steer(0, steer*30.0f, 0);
|
||||
|
||||
@ -866,13 +868,27 @@ void KartModel::update(float dt, float distance, float steer, float speed,
|
||||
else
|
||||
{
|
||||
suspension_length = m_kart->getVehicle()->getWheelInfo(i).
|
||||
m_raycastInfo.m_suspensionLength;
|
||||
m_raycastInfo.m_suspensionLength;
|
||||
}
|
||||
|
||||
// Check documentation of Kart::updateGraphics for the following line
|
||||
pos.Y += m_default_physics_suspension[i]
|
||||
- suspension_length
|
||||
- m_kart_lowest_point;
|
||||
|
||||
// Adjust the wheel position for lean: the lean can cause the 'leaned
|
||||
// to' side to be partly in the ground - which looks ok (like the tyres
|
||||
// being compressed), but the other side will be in the air. To avoid
|
||||
// this, increase the position of the wheels on the side that are
|
||||
// higher in the ground so that the wheel still touch the ground.
|
||||
if(current_lean_angle > 0 && (i&1) == 0) // i&1 == 0: left side
|
||||
{
|
||||
pos.Y -= current_lean_angle;
|
||||
}
|
||||
else if (current_lean_angle < 0 && (i&1) == 1) // i&1 == 1: right side
|
||||
{
|
||||
pos.Y += current_lean_angle;
|
||||
}
|
||||
m_wheel_node[i]->setPosition(pos);
|
||||
|
||||
// Now calculate the new rotation: (old + change) mod 360
|
||||
|
@ -238,6 +238,7 @@ public:
|
||||
bool loadModels(const KartProperties &kart_properties);
|
||||
void setDefaultSuspension();
|
||||
void update(float dt, float distance, float steer, float speed,
|
||||
float current_lean_angle,
|
||||
int gt_replay_index = -1);
|
||||
void finishedRace();
|
||||
scene::ISceneNode*
|
||||
|
@ -300,7 +300,7 @@ void FeatureUnlockedCutScene::init()
|
||||
m_unlocked_stuff[n].m_root_gift_node = kart_model->attachModel(true, false);
|
||||
m_unlocked_stuff[n].m_scale = 5.0f;
|
||||
kart_model->setAnimation(KartModel::AF_DEFAULT);
|
||||
kart_model->update(0.0f, 0.0f, 0.0f, 0.0f); // set model current frame to "center"
|
||||
kart_model->update(0.0f, 0.0f, 0.0f, 0.0f, 0.0f); // set model current frame to "center"
|
||||
|
||||
#ifdef DEBUG
|
||||
m_unlocked_stuff[n].m_root_gift_node->setName("unlocked kart");
|
||||
|
Loading…
Reference in New Issue
Block a user