Added maximum height difference to detect if a target is

close enough for a rubber ball. This avoids a problem is 
the target is actually close on a different part of the
track.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9996 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-10-16 12:17:56 +00:00
parent d9ada38dcf
commit 830e88d1e5
3 changed files with 32 additions and 5 deletions

View File

@ -48,10 +48,11 @@
model="rubber_ball.b3d" speed="35.0"
scale="1 1 1" interval="1"
max-height="4.0" min-height="0"
fast-ping-distance="50"
target-distance="50" target-max-angle = "90"
min-interpolation-distance="10"
squash-slowdown="0.5" squash-duration="3"
delete-time="5.0" />
delete-time="5.0" max-height-difference="10" />
<item name="parachute" icon="parachute-icon.png"
model="parachute.b3d" />
<item name="plunger" icon="plunger-icon.png"

View File

@ -35,6 +35,8 @@ float RubberBall::m_st_squash_slowdown;
float RubberBall::m_st_target_distance;
float RubberBall::m_st_target_max_angle;
float RubberBall::m_st_delete_time;
float RubberBall::m_st_max_height_difference;
float RubberBall::m_fast_ping_distance;
int RubberBall::m_next_id = 0;
RubberBall::RubberBall(Kart *kart, Track* track)
@ -75,7 +77,7 @@ RubberBall::RubberBall(Kart *kart, Track* track)
// initialises the current graph node
TrackSector::update(getXYZ(), kart, track);
TrackSector::update(getXYZ(), kart, m_track);
initializeControlPoints(m_owner->getXYZ());
// At the start the ball aims at quads till it gets close enough to the
@ -227,6 +229,8 @@ void RubberBall::init(const XMLNode &node, scene::IMesh *bowling)
m_st_target_distance = 50.0f;
m_st_target_max_angle = 25.0f;
m_st_delete_time = 10.0f;
m_st_max_height_difference = 10.0f;
m_fast_ping_distance = 50.0f;
if(!node.get("interval", &m_st_interval))
printf("[powerup] Warning: no interval specified for rubber ball.\n");
@ -251,6 +255,15 @@ void RubberBall::init(const XMLNode &node, scene::IMesh *bowling)
printf(
"[powerup] Warning: no target-max-angle specified for rubber ball.\n");
m_st_target_max_angle *= DEGREE_TO_RAD;
if(!node.get("max-height-difference", &m_st_max_height_difference))
printf(
"[powerup] Warning: no max-height-difference specified for "
"rubber ball.\n");
if(!node.get("fast-ping-distance", &m_fast_ping_distance))
printf(
"[powerup] Warning: no fast-ping-distancespecified for "
"rubber ball.\n");
Flyable::init(node, bowling, PowerupManager::POWERUP_RUBBERBALL);
} // init
@ -546,10 +559,10 @@ void RubberBall::checkDistanceToTarget()
m_target->getXYZ().getZ(),diff
);
if(diff < m_st_target_distance)
if(diff < m_st_target_distance &&
fabsf(m_target->getXYZ().getY() - getXYZ().getY()) <
m_st_max_height_difference )
{
printf("target-height %f ball-height %f\n",
m_target->getXYZ().getY(), getXYZ().getY());
m_aiming_at_target = true;
return;
}

View File

@ -55,6 +55,19 @@ private:
* start to aim directly at the target (and not interpolate anymore). */
static float m_st_target_distance;
/** In somce track, e.g. subsea track, it is possible that the karts
* are on different parts of the track (different shortcuts), but
* still close to each other - because one of the parts is just
* on top of the other part. Therefore use the height as additional
* criteria to determine if a ball is close to its target. */
static float m_st_max_height_difference;
/** Distance between ball and target at which the ball will start to
* bounce faster (which makes more 'ping' sfx for the driver to
* hear it coming closer, but also higher probability to hit the
* target and not fly over it). */
static float m_fast_ping_distance;
/** The maximum angle the ball can change per second when being close
* to the taregt. If the target angle is small, it makes it much harder
* to hit the target, giving it some chances to escape. */