Fix all known instances of kart flying due to cushioning

This commit is contained in:
Alayan 2018-09-20 23:56:53 +02:00
parent 0da04805b4
commit 6dedbff1a8
3 changed files with 19 additions and 11 deletions

View File

@ -25,6 +25,7 @@
#include "karts/kart_properties.hpp" #include "karts/kart_properties.hpp"
#include "modes/three_strikes_battle.hpp" #include "modes/three_strikes_battle.hpp"
#include "network/network_config.hpp" #include "network/network_config.hpp"
#include "physics/btKart.hpp"
#include "physics/physics.hpp" #include "physics/physics.hpp"
#include "physics/triangle_mesh.hpp" #include "physics/triangle_mesh.hpp"
#include "tracks/drive_graph.hpp" #include "tracks/drive_graph.hpp"
@ -60,6 +61,7 @@ RescueAnimation::RescueAnimation(AbstractKart *kart, bool is_auto_rescue)
m_up_vector = m_kart->getTrans().getBasis().getColumn(1); m_up_vector = m_kart->getTrans().getBasis().getColumn(1);
m_xyz = m_kart->getXYZ(); m_xyz = m_kart->getXYZ();
m_kart->getAttachment()->clear(); m_kart->getAttachment()->clear();
m_kart->getVehicle()->resetGroundHeight();
if (NetworkConfig::get()->isNetworking() && if (NetworkConfig::get()->isNetworking() &&
NetworkConfig::get()->isServer()) NetworkConfig::get()->isServer())

View File

@ -131,14 +131,22 @@ void btKart::reset()
m_max_speed = -1.0f; m_max_speed = -1.0f;
m_min_speed = 0.0f; m_min_speed = 0.0f;
m_cushioning_disable_time = 0; m_cushioning_disable_time = 0;
m_ground_height = 0; resetGroundHeight();
m_ground_height_old = 0;
// Set the brakes so that karts don't slide downhill // Set the brakes so that karts don't slide downhill
setAllBrakes(5.0f); setAllBrakes(5.0f);
} // reset } // reset
// ----------------------------------------------------------------------------
/** Resets the ground height of a kart. This is also called on rescues.
*/
void btKart::resetGroundHeight()
{
m_ground_height = 0.15;
m_ground_height_old = 0.15;
} // resetGroundHeight
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const btTransform& btKart::getWheelTransformWS( int wheelIndex ) const const btTransform& btKart::getWheelTransformWS( int wheelIndex ) const
{ {
@ -530,7 +538,7 @@ void btKart::updateVehicle( btScalar step )
btVector3 down = -m_chassisBody->getGravity(); btVector3 down = -m_chassisBody->getGravity();
down.normalize(); down.normalize();
btVector3 v_down = (v * down) * down; btVector3 v_down = (v * down) * down;
btScalar offset=0.1f; btScalar offset=0.24;
#ifdef DEBUG_CUSHIONING #ifdef DEBUG_CUSHIONING
Log::verbose("physics", Log::verbose("physics",
@ -551,18 +559,15 @@ void btKart::updateVehicle( btScalar step )
// to the predicted kart movement, which was found experimentally: // to the predicted kart movement, which was found experimentally:
btScalar gravity = m_chassisBody->getGravity().length(); btScalar gravity = m_chassisBody->getGravity().length();
btScalar absolute_fall = step*(-v_down.getY() + gravity*step);
btScalar predicted_fall = gravity*step*step + btScalar predicted_fall = gravity*step*step +
(m_ground_height_old-m_ground_height); (m_ground_height_old-m_ground_height);
// Limit kart jumping upward brutally if landing just // if the ground_height is below offset-0.01f ;
// after a sudden terrain height change ; // the terrain has unexpectedly changed - avoid sending the kart flying
// no jump in STK is so big to normally go over this value if (absolute_fall > 0.06 && m_cushioning_disable_time==0 &&
if (predicted_fall > 0.4) predicted_fall = 0.4;
if (v_down.getY()<0 && m_cushioning_disable_time==0 &&
m_ground_height < predicted_fall + offset && m_ground_height < predicted_fall + offset &&
m_ground_height > 0 && m_ground_height_old > 0.3 && m_ground_height > (offset-0.01f) && m_ground_height_old > 0.3)
predicted_fall > 0.05)
{ {
// Disable more cushioning for 1 second. This avoids the problem // Disable more cushioning for 1 second. This avoids the problem
// of hovering: a kart gets cushioned on a down-sloping area, still // of hovering: a kart gets cushioned on a down-sloping area, still

View File

@ -148,6 +148,7 @@ public:
Kart *kart); Kart *kart);
virtual ~btKart(); virtual ~btKart();
void reset(); void reset();
void resetGroundHeight();
void debugDraw(btIDebugDraw* debugDrawer); void debugDraw(btIDebugDraw* debugDrawer);
const btTransform& getChassisWorldTransform() const; const btTransform& getChassisWorldTransform() const;
btScalar rayCast(unsigned int index, float fraction=1.0f); btScalar rayCast(unsigned int index, float fraction=1.0f);