Game Development Reference
In-Depth Information
back buffer is cleared to prepare it for drawing upon and ultimately copying to the
screen.
Finally, the last four lines of code wrap the hovercraft's position around the edges of the
screen.
Tuning
You'll probably want to tune this example to run well on your computer since we didn't
implement any profiling for processor speed. Moreover, you should tune the various
parameters governing the behavior of the hovercraft to see how it responds. The way
we have it set up now makes the hovercraft exhibit a soft sort of response to turning—
that is, upon application of turning forces, the craft will tend to keep tracking in its
original heading for a bit even while yawed. It will not respond like a car would turn.
You can change this behavior, of course.
Some things we suggest you play with include the time step size and the various con‐
stants we've defined as follows:
#define _THRUSTFORCE 5.0f
#define _MAXTHRUST 10.0f
#define _MINTHRUST 0.0f
#define _DTHRUST 0.001f
#define _STEERINGFORCE 3.0f
#define _LINEARDRAGCOEFFICIENT 1.25f
_THRUSTFORCE is the initial magnitude of the propeller thrust force. _MAXTHRUST and
_MINTHRUST set upper and lower bounds to this force, which is modulated by the user
pressing the up and down arrow keys. _DTHRUST is the incremental change in thrust in
response to the user pressing the up and down arrow keys. _STEERINGFORCE is the mag‐
nitude of the bow thruster forces. You should definitely play with this value to see how
the behavior of the hovercraft changes. Finally, _LINEARDRAGCOEFFICIENT is the drag
coefficient used to compute aerodynamic drag. This is another good value to play with
to see how behavior is affected. Speaking of drag, the location of the center of drag that's
initialized in the RigidBody2D constructor is a good parameter to change in order to
understand how it affects the behavior of the hovercraft. It influences the craft's direc‐
tional stability, which affects its turning radius—particularly at higher speeds.
Search Nedrilad ::




Custom Search