Game Development Reference
In-Depth Information
Applying forces
In the source code for this section, BasicDemo has been modified to grab the G key,
and apply a force of 20 units in the y axis to the first box (the red one). This is strong
enough to counteract the force of gravity (default of -10 in the y axis), and cause our
object to accelerate upwards while the key is held down.
Check the Keyboard() , KeyboardUp() , and UpdateScene() functions of
BasicDemo to see this process in action.
Note
Note that each of the override functions used in this process begins by calling
back to the base class implementation of the same function. This ensures that
our base class code, which handles keyboard input and scene updating, is still
called before we do anything unique in our derived class.
Launch our application and try pressing and holding the G key. Our first box should
now begin to float. The following screenshot shows how our first box can be lifted up,
land back in the trigger volume, and summon even more boxes:
Search WWH ::




Custom Search