Made z-velocity adjustment for flyables optional. Disabling this
fixed the gravity handling for the bowling ball. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2280 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -47,7 +47,13 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, COLLECT_BOWLING)
|
||||
}
|
||||
|
||||
createPhysics(y_offset, btVector3(0.0f, m_speed*2, 0.0f),
|
||||
new btSphereShape(0.5f*m_extend.getY()), true /*gravity*/, true /*rotates*/);
|
||||
new btSphereShape(0.5f*m_extend.getY()),
|
||||
true /*gravity*/,
|
||||
true /*rotates*/);
|
||||
|
||||
// Do not adjust the z velociy depending on height above terrain, since
|
||||
// this would disable gravity.
|
||||
setAdjustZVelocity(false);
|
||||
|
||||
// unset no_contact_response flags, so that the ball
|
||||
// will bounce off the track
|
||||
@@ -73,10 +79,10 @@ void Bowling::init(const lisp::Lisp* lisp, ssgEntity *bowling)
|
||||
// -----------------------------------------------------------------------------
|
||||
void Bowling::update(float dt)
|
||||
{
|
||||
Flyable::update(dt);
|
||||
Flyable::update(dt);
|
||||
const Kart *kart=0;
|
||||
btVector3 direction;
|
||||
float minDistance;
|
||||
btVector3 direction;
|
||||
float minDistance;
|
||||
getClosestKart(&kart, &minDistance, &direction);
|
||||
if(minDistance<m_st_max_distance_squared) // move bowling towards kart
|
||||
{
|
||||
|
||||
@@ -52,6 +52,7 @@ Flyable::Flyable(Kart *kart, CollectableType type, float mass) : Moveable(false)
|
||||
m_exploded = false;
|
||||
m_shape = NULL;
|
||||
m_mass = mass;
|
||||
m_adjust_z_velocity = true;
|
||||
|
||||
// Add the graphical model
|
||||
ssgTransform *m = getModelTransform();
|
||||
@@ -170,17 +171,19 @@ void Flyable::update (float dt)
|
||||
explode(NULL); // flyable out of track boundary
|
||||
return;
|
||||
}
|
||||
if(m_adjust_z_velocity)
|
||||
{
|
||||
float hat = pos.getZ()-getHoT();
|
||||
|
||||
float hat = pos.getZ()-getHoT();
|
||||
|
||||
// Use the Height Above Terrain to set the Z velocity.
|
||||
// HAT is clamped by min/max height. This might be somewhat
|
||||
// unphysical, but feels right in the game.
|
||||
hat = std::max(std::min(hat, m_max_height) , m_min_height);
|
||||
float delta = m_average_height - hat;
|
||||
btVector3 v=getVelocity();
|
||||
v.setZ(m_force_updown*delta);
|
||||
setVelocity(v);
|
||||
// Use the Height Above Terrain to set the Z velocity.
|
||||
// HAT is clamped by min/max height. This might be somewhat
|
||||
// unphysical, but feels right in the game.
|
||||
hat = std::max(std::min(hat, m_max_height) , m_min_height);
|
||||
float delta = m_average_height - hat;
|
||||
btVector3 v=getVelocity();
|
||||
v.setZ(m_force_updown*delta);
|
||||
setVelocity(v);
|
||||
} // if m_adjust_z_velocity
|
||||
|
||||
Moveable::update(dt);
|
||||
} // update
|
||||
|
||||
@@ -34,8 +34,12 @@ private:
|
||||
bool m_has_hit_something;
|
||||
/** This flag is used to avoid that a rocket explodes mode than once.
|
||||
* It can happen that more than one collision between a rocket and
|
||||
* a track or kart is reported by the physics. */
|
||||
* a track or kart is reported by the physics. */
|
||||
bool m_exploded;
|
||||
/** If this flag is set, the Z velocity of the kart will not be
|
||||
* adjusted in case that the objects is too high or too low above the
|
||||
* terrain. Otherwise gravity will not work correctly on this object. */
|
||||
bool m_adjust_z_velocity;
|
||||
|
||||
protected:
|
||||
Kart* m_owner; // the kart which released this flyable
|
||||
@@ -74,6 +78,10 @@ public:
|
||||
|
||||
Flyable (Kart* kart, CollectableType type, float mass=1.0f);
|
||||
virtual ~Flyable ();
|
||||
/** Enables/disables adjusting ov velocity depending on height above
|
||||
* terrain. Missiles can 'follow the terrain' with this adjustment,
|
||||
* but gravity will basically be disabled. */
|
||||
void setAdjustZVelocity(bool f) { m_adjust_z_velocity = f; }
|
||||
static void init (const lisp::Lisp* lisp, ssgEntity *model,
|
||||
CollectableType type);
|
||||
virtual void update (float);
|
||||
|
||||
Reference in New Issue
Block a user