Make hiker happy

This commit is contained in:
Alayan 2018-09-25 19:46:28 +02:00
parent 4a39813f07
commit 69ee902327
2 changed files with 12 additions and 54 deletions

View File

@ -22,7 +22,6 @@
#include "LinearMath/btIDebugDraw.h"
#include "BulletDynamics/ConstraintSolver/btContactConstraint.h"
#include "config/stk_config.hpp"
#include "graphics/material.hpp"
#include "karts/kart.hpp"
#include "karts/kart_model.hpp"
@ -131,23 +130,12 @@ void btKart::reset()
m_max_speed = -1.0f;
m_min_speed = 0.0f;
m_cushioning_disable_time = 0;
resetGroundHeight();
// Set the brakes so that karts don't slide downhill
setAllBrakes(5.0f);
} // 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;
m_max_ground_height = 0.15;
} // resetGroundHeight
// ----------------------------------------------------------------------------
const btTransform& btKart::getWheelTransformWS( int wheelIndex ) const
{
@ -289,10 +277,10 @@ btScalar btKart::rayCast(unsigned int index, float fraction)
btScalar max_susp_len = wheel.getSuspensionRestLength()
+ wheel.m_maxSuspensionTravel;
// Do a longer raycast to see if the kart might soon hit the
// Do a slightly longer raycast to see if the kart might soon hit the
// ground and some 'cushioning' is needed to avoid that the chassis
// hits the ground.
btScalar raylen = max_susp_len*10 + 0.5f;
btScalar raylen = max_susp_len + 0.5f;
btVector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
const btVector3& source = wheel.m_raycastInfo.m_hardPointWS;
@ -308,11 +296,6 @@ btScalar btKart::rayCast(unsigned int index, float fraction)
wheel.m_raycastInfo.m_groundObject = 0;
btScalar depth = raylen * rayResults.m_distFraction;
if (depth < m_ground_height)
m_ground_height = depth;
if (depth > m_max_ground_height)
m_max_ground_height = depth;
if (object && depth < max_susp_len)
{
wheel.m_raycastInfo.m_contactNormalWS = rayResults.m_hitNormalInWorld;
@ -534,18 +517,17 @@ void btKart::updateVehicle( btScalar step )
if(m_cushioning_disable_time>0) m_cushioning_disable_time --;
bool needed_cushioning = false;
btVector3 v =
m_chassisBody->getVelocityInLocalPoint(m_wheelInfo[wheel_index]
.m_chassisConnectionPointCS);
btVector3 down = -m_chassisBody->getGravity();
down.normalize();
btVector3 v_down = (v * down) * down;
btScalar offset=0.24;
btScalar offset=0.1f;
#ifdef DEBUG_CUSHIONING
Log::verbose("physics",
"World %d wheel %d lsuspl %f vdown %f overall speed %f length %f",
"World %d wheel %d lsuspl %f vdown %f overall speed %f lenght %f",
World::getWorld()->getTimeTicks(),
wheel_index,
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength,
@ -561,30 +543,19 @@ void btKart::updateVehicle( btScalar step )
// predict the upcoming collision correcty - so we add an offset
// to the predicted kart movement, which was found experimentally:
btScalar gravity = m_chassisBody->getGravity().length();
btScalar absolute_fall = step*(-v_down.getY() + gravity*step);
btScalar predicted_fall = gravity*step*step +
(m_ground_height_old-m_ground_height);
// if the ground height is below offset-0.01f, if predicted_fall > 0.4,
// or if max ground height is significantly different,
// the terrain has unexpectedly changed - avoid sending the kart flying
// TODO : check length between front and back wheels
if (absolute_fall > 0.06 && m_cushioning_disable_time==0 &&
m_ground_height < predicted_fall + offset &&
m_ground_height > (offset-0.01f) && m_ground_height_old > 0.3 &&
predicted_fall < 0.4 && m_max_ground_height > 0 &&
m_max_ground_height < 0.8)
if (v_down.getY()<0 && m_cushioning_disable_time==0 &&
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength
< step * (-v_down.getY()+gravity*step)+offset)
{
// Disable more cushioning for 1 second. This avoids the problem
// of hovering: a kart gets cushioned on a down-sloping area, still
// moves forwards, gets cushioned again etc. --> kart is hovering
// and not controllable.
m_cushioning_disable_time = stk_config->time2Ticks(1);
m_cushioning_disable_time = 120;
needed_cushioning = true;
btVector3 impulse = down * (predicted_fall/step)
/ m_chassisBody->getInvMass();
btVector3 impulse = down * (-v_down.getY() + gravity*step)
/ m_chassisBody->getInvMass();
#ifdef DEBUG_CUSHIONING
float v_old = m_chassisBody->getLinearVelocity().getY();
#endif
@ -592,13 +563,12 @@ void btKart::updateVehicle( btScalar step )
#ifdef DEBUG_CUSHIONING
Log::verbose("physics",
"World %d Cushioning imp %f vdown %f from %f m/s to %f m/s "
"height %f contact %f kart %f susp %f relspeed %f",
"contact %f kart %f susp %f relspeed %f",
World::getWorld()->getTimeTicks(),
impulse.getY(),
-v_down.getY(),
v_old,
m_chassisBody->getLinearVelocity().getY(),
m_ground_height,
m_wheelInfo[wheel_index].m_raycastInfo.m_isInContact ?
m_wheelInfo[wheel_index].m_raycastInfo.m_contactPointWS.getY()
: -100,
@ -609,10 +579,6 @@ void btKart::updateVehicle( btScalar step )
);
#endif
}
// Update the ground height history
m_ground_height_old = m_ground_height;
m_ground_height = 999.9f;
m_max_ground_height = -100.0f;
// Update friction (i.e. forward force)

View File

@ -11,8 +11,6 @@
#ifndef BT_KART_HPP
#define BT_KART_HPP
#include <vector>
#include "BulletDynamics/Dynamics/btRigidBody.h"
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
#include "physics/btKartRaycast.hpp"
@ -119,12 +117,6 @@ private:
* physics steps, so need to be set again by the application. */
btScalar m_max_speed;
/** Smallest wheel height to the ground */
btScalar m_ground_height;
btScalar m_ground_height_old;
/** Highest wheel height to the ground (to detect brutal changes) */
btScalar m_max_ground_height;
/** True if the visual wheels touch the ground. */
bool m_visual_wheels_touch_ground;
@ -150,7 +142,6 @@ public:
Kart *kart);
virtual ~btKart();
void reset();
void resetGroundHeight();
void debugDraw(btIDebugDraw* debugDrawer);
const btTransform& getChassisWorldTransform() const;
btScalar rayCast(unsigned int index, float fraction=1.0f);
@ -301,3 +292,4 @@ public:
}; // class btKart
#endif //BT_KART_HPP