Computing Magazine

Godot Engine Game Tutorial for Beginners – Create a 2D Racing Game 2

Posted on the 31 December 2016 by Codetuto

This is the second part of the 2d car racing game tutorial series. As I already said in the previous post, we are making this game in the awesome opensource free Godot Engine and to help the new comers, this game tutorial is targeted towards beginners.

If you don't have the project ready, please go through the part 1 of this series and follow it and set your project ready. You can also download the ready made project from the same post.

In this post, we are going to create enemy cars, roadblocks and barrels. First of all download all the assets required for this part from here. Then copy all images to 'assets/images' folder.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Create enemy cars

The enemy cars are different from the player car in colour and are more colourful than our white Player car. We can create the enemy car from scratch, but we already have a basic Player car setup from our previous part. Click the 'Clapperboard' icon on the Player node and choose Open in Editor to open the Player scene in a new tab.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Rename the node 'Player' to 'Enemy'. Now save the scene as Enemy.tscn in 'packed/enemy' folder.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Click on the Sprite node and change its texture to car1.png. Make sure to disable mipmaps for this texture. If you don't know how to disable mipmapping, it is explained in the previous part of this tutorial series. Yeah you definitely need to read it.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

That's it and our Enemy scene is complete. We don't need to create different enemy scenes for all the colours, we will switch the texture later using script. Yes, there are some scripting involved in this game, but don't go away, it is very simple.

Create the Barrel

Create a new scene, add a RigidBody2D, add a Sprite and a CollisionShape2D.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Rename the RigidBody2D node to 'Barrel'. Then set the texture for the sprite node.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

To set the collision, set the collision shape as RectangleShape2D, and define the shape by dragging the inner dots. Move the shape and align the bottom and sides to perfectly fit for the sprite.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Save the scene as Barrel.tscn inside the 'packed/barrel' folder.

Create the Roadblock

Creating the roadblock is the same process as creating the barrel. The textures and collision shape are going to be different this time.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Set the texture for Sprite as 'roadblock.png' and for the collision shape, choose SegmentShape2D. SegmentShape2D is just a line where objects collide to. We could use SegmentShape2D for the barrel scene also. But I thought you will understand better when you do the same thing again and again. So I didn't introduce a new one for the barrel.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

After selecting the SegmentShape2D, drag those inner dot handles as shown below to setup the shape.

Godot Engine game tutorial for beginners – Create a 2D Racing Game 2

Save the scene as RoadBlock.tscn inside the packed/roadblock folder.

Godot Engine game tutorial for beginners - Create a 2D Racing Game 2 Click To Tweet

That's all and in the next part, we will begin actual scripting. Thanks for reading.

You can download the project here.

[Total: 1 Average: 5/5]


Back to Featured Articles on Logo Paperblog