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.
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.
Rename the node ‘Player’ to ‘Enemy’. Now save the scene as Enemy.tscn in ‘packed/enemy’ folder.
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.
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.
Rename the RigidBody2D node to ‘Barrel’. Then set the texture for the sprite node.
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.
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.
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.
After selecting the SegmentShape2D, drag those inner dot handles as shown below to setup the shape.
Save the scene as RoadBlock.tscn inside the packed/roadblock folder.
That’s all and in the next part, we will begin actual scripting. Thanks for reading.
You can download the project here.
[Total: 17 Average: 3.5/5]