Now, we need to add blocks to the game. Click on the block
sprite and add a Physics behavior.
Put the block in front of the cannonball and test it out by firing the cannon! This is shown in the following screenshot:
The cannonball just sits on the screen and doesn't move. We should then add some logic to destroy it after it hits a block. Add a Compare velocity event to the cannonBall
sprite.
The velocity that we are going to compare is Overall velocity, and we are going to set Comparison to ≤ Less or equal with value 0.1
. This is shown in the following screenshot. The reason we don't want to set the value to zero is that our object may still have a tiny amount of velocity (for instance, of value 0.00001); but as it has not quite made it to zero, the event would not be activated.
When the cannonball almost comes to a complete stop, we want to destroy it. Add a Destroy object action to the event, as shown in the following screenshot:
Run the game. When the cannonball stops, it is reset very abruptly. In order to make this easier for the game to handle, we will add a Wait action.
Let's wait for a few seconds; we will set the value of Seconds to 2.5
seconds, as shown in the following screenshot:
We also need to move the action up in the order of actions. Highlight it and drag it to the top. Remember that the actions are read line by line, which means that the first action will happen first, and so on. In this case, it will wait for 2.5 seconds and then destroy the object. Run the game and try it out.
3.142.166.31