Game Development Reference
In-Depth Information
Applying force at an angle
Run the game again.
You will notice that the ball just falls down! Now that we have added physics, we can add a
force to the cannonball to make it shoot like real cannon. Add an action to the Mouse click
event. The action will be Apply force at angle , as shown in the following screenshot:
Set the force to around 200 . The bigger the number, the further the cannonball travels. For
the angle, type in cannon.Angle as shown in the following screenshot. This will ensure
that the cannonball is shot in the same direction as the cannon.
Setting cannonballs to fire one at a time
If you run the game, you will notice that we can fire as many cannonballs as we want. We
should limit the cannonballs to make them fire only one at a time. In order to do this, we
need to add a global variable. Let's name this variable canFire and set its initial value to
0 , as shown in the following screenshot:
Search WWH ::




Custom Search