GDevelop Physics Launch Tutorial – Part 4

In this tutorial series, we are creating a physics-based game similar to that of Angry Birds using the GDevelop game engine. In part 3 we really improved the slingshot, making it easier to aim and more attractive visually. Now in part 4 we’re going to add some things to fire at and add some finishing touches.

If you want to jump on to the tutorial from this part, you can find the finished result from part 3 right here: Part 3 Result.

Adding something to aim at

Let’s start by adding something we can aim and hit with our slingshot. Open up “Game_Scene” and create a new object. Select “Sprite” and name it “Wood_Box”. Add an animation and add the image at “Assets/Wooden elements/elementWood010.png”.

Next, go to “Behaviors”. Similarly to the player_alien in part 1, we’re going to add a behavior to destroy the object when it’s outside of the screen and we’re going to add a behavior to enable physics. First, click “+ ADD BEHAVIOR TO THE OBJECT” and search for “Destroy”. Select “Destroy when outside of the screen”.

Next, click “+ ADD BEHAVIOR TO THE OBJECT” again but this time search for “Physics”. Select “Physics Engine 2.0”. This is going to add a bunch of different properties, but we’re only going to focus on the type and shape in this tutorial. Make sure the type property is set to “Dynamic” and that the shape is set to “Box”. Then set the “width” to 70 and the “height” to 70.

This is what it should look something like when fully setup:

When it’s all setup, hit “Apply”. Now before we can add it to the scene, we need some platforms for it to rest on, so let’s add that next.

Make a new object by pressing the “Add a new object”. Select “Sprite” and name the object “Grass_Block”. Add a new animation and set the image to “Assets/Other/grass.png”. Next, go to the “Behaviors” tab on the top and add a new behavior. Search for “Physics” and add “Physics Engine 2.0”.

This time, we need to do things a little differently. Set the type to “Static” instead of “Dynamic” like we’ve been doing so far. We want to do this because this time we don’t want the physics engine to move this object automatically, we just want it to stay in place so it can hold and collide with other physics objects.

Next, set the shape to “Box” and set the “Width” to “70” and the height to “70”. When all setup, it should look something like this:

Once it’s all setup, hit “Apply”. Now we can drag and drop the a few Grass_Block objects and Wooden_Box objects into the scene. How you design it is up to you, just make sure that you can hit all the blocks as that will be important in just a little bit.

Here’s how I have the Grass_Block objects and Wooden_Bock objects setup in my scene for example:

If you play the game now, you can fire balls at the boxes and watch them fall off the screen!

Finishing Touches

Let’s add some final finishing touches to the project. First, let’s track how many balls the player has launched from the slingshot and show the number to the player. First, add a new object and select “Text”. Name the object “Ball_Launch_Display” and set the “initial text to display” to “Balls Launched: 0”. Next, drag and drop it into the scene and position it near the bottom right corner of the camera rectangle. Here’s where I placed mine:

Once you have the “Ball_Launch_Display” text placed where you like, open the “Game_Scene (Events)” tab.

First, in the “At the beginning of the scene” event, add a new action just under “Hide Touch_Start_Pos”. Search “Scene Variable” and then select “Value of a scene variable”. Next, click the little blue icon on the far right side of the “Variable” property so we can add a new scene variable. In the Scene Variables window, press the “+ ADD” button and name the new variable “Balls_Launched”. Then select the little wrench icon and select “Primitive types/Convert to number” and leave it at the default of 0. When finished, it should look something like this:

Finally, hit “Apply”.

Next, set the “Variable” property of the action to “Balls_Launched”, set the “Modification’s sign” to “= (set to)” and set the value to “0”. This is so if we change scenes, the variable we are using to track the number of balls launched is reset to 0. While we are not tackling different levels in this tutorial currently, if we did add multiple levels or a level selection menu, we’d want to make sure we properly reset the number of balls launched.

Next, we need to increase this new scene variable whenever we create a new Player_Alien object. In the event with “Create object Player_Alien at position Slingshot_Repsawn_Point …” add a new action. Search for “Scene variable” and select “Value of a scene variable”. Then set the “Variable” property to “Balls_Launched”, the modification sign to “+ (add)” and set the value to “1”. This will add one to the “Balls_Launched” scene variable anytime we create a new ball with the slingshot, which is exactly what we want.

Finally, add another new action right under the one we just added, “Change the scene_variable Balls_Launched: add 1”. Select “Ball_Launch_Display” and search “Modify”. Select “Modify the text”. In the properties, set “Modification’s sign” to “= (set to)” and set the value to "Balls Launched: " + ToString(Variable(Balls_Launched)).


Note that you need to add ” to either side of the text “Balls Launched: ” so it is recognized as a string (text). Without adding those quotes, it will not set the text properly and will not work.

Go ahead and try the project! Now when you fire balls from the slingshot, the text at the bottom right of the screen should increase as you shoot balls from the slingshot.

Next, let’s track if all the boxes have been removed and if they have, show the player some text telling them they have won the game.

First, make a new object and select “Text”. Name the object “Gameover_Display” and set the font “Size” to “54”. Set the “Initial text to display” to something like “Gameover: You win!” and hit apply. Drag the object into the scene and position it near the top center of the camera view. For example, here is where I have placed it:

Now before we add some events to make it function correctly, let’s add all of the objects we want to track to a new group. In this case we’re just wanting to know if all the wooden boxes are destroyed, but if we ever wanted to add new boxes or anything else, having a group would be helpful. By using a group, we can track all of the objects in the group and see if all of them are destroyed easily, while it would be much more difficult if we had to check each object at a time.

In the “Object Groups” window, click the “Click to add a group” button or the “+”:

This will add a new group. Hit the three vertical dots icon and rename the group to “Level_Objects”. Then click the “Level_Objects” group and in the window that pops up, select “Choose an object to add to the group” and select “Wooden_Box”. This will add the object to the group. If we had different sizes boxes or different shaped boxes, we could also add them to this group, but for now, just hit “Apply”.

Now let’s add the events to track whether the player has removed all the objects in “Level_Objects” or not. Open “Game_Scene (Events)” and add a new action to “At the beginning of the scene”. Select “Gameover_Display”, search for “visibility” and select “Hide”.

Then add a new event and select “Add condition”. Select the “Level_Objects” group and then search for “number”. Select “Number of objects”. In the properties, set the “Sign of the test” to “<= (less or equal to)” and set the “Value to compare” to “0”:

Next, add an action by pressing “Add action”. Select “Gameover_Display” and search for visibility. Select “Show” and then hit “OK”.

Here’s how the events look like with everything added:

Give the game a try! Now when all of the boxes have fallen off the screen, the text should appear telling the player they have won the game!

Series Finish

Now you have a working physics-based game that is similar to Angry Birds in it’s mechanics. Now, there are still plenty of things we could add to the game, like multiple levels, sounds, blocks that can be damaged and destroyed, and more, but this is a good starting point for many different types of games.

For example, the same drag and launch mechanic could be used for a golf game, where you try to get a golf ball to the hole in as few of strokes as you can.

However, for this tutorial series, we’ll leave the project here for now. You can find the finished project for part 4 right here: Part 4 finished.

The finished prototype project! Fundamentally the same as we made in this series!

You can also find the project I used to prototype and implement this tutorial series here: Finished project.

It has several additional features like multiple levels, balls that disappear after a few seconds, and a simple game over scene, but fundamentally its exactly the same as the project we made in this tutorial. If you are curious to see how it works, there are comments in the finished prototype project that briefly explain each part.

Thanks for reading this tutorial! If you have any suggestions, feedback, or ideas for future tutorials, please let me know! You can reach me here on Twitter if you have any feedback! While you are there, please consider following if you liked this tutorial so you don’t miss any future tutorials or other projects I work on!