Game Development Reference
In-Depth Information
ï?®
A spring is 0.5×0.5 meters, talking up half a cell in each direction. The spring
is actually a little bit taller than it is wide. We make its bounding shape
square so that the collision testing is a bit more forgiving.
ï?®
A squirrel is 1×0.8 meters.
ï?®
A castle is 1.8×1.8 meters.
With those sizes, we also have the sizes of the bounding rectangles of our objects for collision
detection. We can adjust them if they turn out to be a little too big or small, depending on how
the game plays out with those values.
Another thing we can derive from Figure 9-3 is the size of our view frustum. It will show us
10×15 meters of our world.
The only things left to define are the velocities and accelerations we have in the game. These
are highly dependent on how we want our game to feel. Usually, you'd have to do some
experimentation to get those values right. Here's what we came up with after a few iterations of
tuning:
ï?®
The gravity acceleration vector is (0,-13) m/s
2 , slightly more than what we
have here on earth and what we used in our cannon example in Chapter 8.
ï?®
Bob's initial jump velocity vector is (0,11) m/s. Note that the jump velocity
affects the movement only on the y axis. The horizontal movement will be
defined by the current accelerometer readings.
ï?®
Bob's jump velocity vector will be 1.5 times his normal jump velocity when
he hits a spring. That's equivalent to (0,16.5) m/s. Again, this value is derived
purely from experimentation.
ï?®
Bob's horizontal movement speed is 20 m/s. Note that that's a directionless
speed, not a vector. We'll explain in a minute how that works together with
the accelerometer.
ï?®
The squirrels will patrol from the left to the right and back continuously.
They'll have a constant movement speed of 3 m/s. Expressed as a vector,
that's either (-3,0) m/s if the squirrel moves to the left or (3,0) m/s if the
squirrel moves to the right.
So how will Bob's horizontal movement work? The movement speed we previously defined is
actually Bob's maximum horizontal speed. Depending on how much the player tilts his or her
phone, Bob's horizontal movement speed will be between 0 (no tilt) and 20 m/s (fully tilted to
one side).
We'll use the value of the accelerometer's x axis because our game will run in portrait mode.
When the phone is not tilted, the axis will report an acceleration of 0 m/s 2 . When fully tilted
to the left so that the phone is in landscape orientation, the axis will report an acceleration of
roughly -10 m/s 2 . When fully tilted to the right, the axis will report an acceleration of roughly
10 m/s 2 . All we need to do is normalize the accelerometer reading by dividing it by the
maximum absolute value (10) and then multiplying Bob's maximum horizontal speed by that.
Bob will thus travel 20 m/s to the left or right when the phone is fully tilted to one side and less
if the phone is tilted less. Bob can move around the screen twice per second when the phone
is fully tilted.
 
Search WWH ::




Custom Search