Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
18. September 2017

Click here for the previous section in this tutorial.

Time for the exact same process as pin and lane, except this time rename the RigidBody to BowlingBallRigidBody. The major differences are we used a SphereShape for our collision shape.

clip_image002

Plus, in physics, in addition to setting Sleep off, and Contact Listener on, we increase the Mass to 3. The value doesn’t really matter, this just means our bowling ball is 3x heavier than the pins.

clip_image004

Just for now lets get things rolling (ugh… the puns) and give our ball some initial velocity, so when we play our game, things happen. We will override this in a bit when we implement user control. Simply set the velocity to -15 or so on the Z axis:

clip_image006

Now when you play the game, if you’ve done everything correctly, the ball should roll down the lane and hit the pins.

clip_image008

Almost there! Now let’s add some audio that happens when the ball hits a pin. It’s the exact same process as back when we created our title screen, so I’m not going to go over it again. Just be sure to add the SamplePlayer to the bowling ball like so:

clip_image010

Then go in and create a sample library and add our bowling ball sound effect, in my case Hit.wav.

Now it’s time to do a bit of coding. The BowlingBall is going to be the heart of our game, so let’s add the script to it. Using the same process as back in the title screen, select the BowlingBall root node and attach a new script. Now select the child BowlingBallRigidBody node, switch to the Node tab, select body_enter and hit the Connect button at the bottom right hand corner.

clip_image012

Another window will pop up asking you which node to connect to. Select our BowlingBall node then click Connect.

clip_image014

This will open up the script editor and create a new function for us. Inside the function enter the following code:

func _on_BowlingBall_body_enter( body ):
	var name = body.get_name()
	if name == "PinBody":
		self.get_node("SamplePlayer").play("Hit")

Now when you play the scene, when the bowling ball hits the pins, audio should play!

Handling User Input

** Before you continue… go back to the bowling ball and remove the Linear velocity we added earlier! We are going to handle that manually from this point on! **

Next we need to give the user some control over the bowling ball. First off, we need to create an Input map. We are going to use left and right arrows for moving the ball, well… left and right. Additionally, the space bar will be used to throw the ball.

Go to the Scene -> Project Settings Menu, then switch to the Input Map tab. Now we are going to add an entry. Simply enter LEFT in the text box, then click Add:

clip_image016

Click the + Icon, then select Key

clip_image018

When prompted, press the Left arrow key

clip_image020

Now repeat this process for Right and Space. You can of course map multiple keys to a single ID, so if you wanted LEFT to also trigger when the A key is pressed, or on Left mouse click, you can. Now lets wire our script up to handle input. Simply add or replace the following in your BowlingBall script:

func _ready():
	set_process_input(true)

func _input(event):
	if(event.is_action_released("LEFT")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(-1,0,0))

	if(event.is_action_released("RIGHT")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(1,0,0))
		
	if(event.is_action_released("SPACE")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(0,0,-35))

Great, we can now control our ball, have collisions with pins and audio plays. We are 99% of the way toward a finished game… only one catch… you can only play once… that’s a bit of an issue no? Let’s do a quick and direct reset by reloading the scene when the user presses the R key. Add RESET to the InputMap and append the following code to your _input() function:

	if(event.is_action_released("RESET")):
		get_tree().reload_current_scene()

And our final complete code should look like:

extends Spatial

func _ready():
	set_process_input(true)
	set_process(true)

func _input(event):
	if(event.is_action_released("LEFT")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(-1,0,0))

	if(event.is_action_released("RIGHT")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(1,0,0))
		
	if(event.is_action_released("SPACE")):
		self.get_node("BowlingBallRigidBody").apply_impulse(Vector3(0,0,0),Vector3(0,0,-35))

	if(event.is_action_released("RESET")):
		get_tree().reload_current_scene()

		
func _on_BowlingBallRigidBody_body_enter( body ):
	var name = body.get_name()
	if name == "PinRigidBody":
		self.get_node("SamplePlayer").play("Hit")


And all done, one complete if primitive bowling game!  Once again, here is the video version.

Programming


7. August 2017


With the upcoming release of Godot 3.0, Visual Programming is now officially part of the game engine.  In this tutorial we are going to look at the basics of programming using the new Visual Programming interface.


To get started using Visual Programming, just like using GDScript or other options, you have to attach a script to an object in Godot, like so:

image


In the script creation dialog, you can now select the programming language to use:

image


It will now bring you to the following programming interface:

image


To get started, we need to implement one of the available Godot callbacks.  These are exactly the same as GDScript and represent various different functions that will be called over time by the game engine.  To get started, in the Members section, click the following icon:

image


The various different callback functions available for the selected object type are available:

image


The most commonly used callbacks are _process() which is called every pass through the game loop, _ready() which is called when the object has been created, _init() which is called to create the object (think constructor), and _input() which is called when input is received.  We are going to create an exceedingly simple example here that moves our sprite each from, so select _process.  Now you should see:

image


White arrows represent program flow.  Connections on the right represent output, while connections on the left represent input.  This is the entry point for our code and is going to be called each frame.  You can see we are passed a floating point value “delta” as a parameter.  Now we need to get a reference to our object, we use a “self” node for this.  You can locate notes via search:

g1


This gives us access to the Sprite object our script is attached.

image


Now click on the blue/green ball output from the Sprite and drag a connection out, selecting Get as the option:

g2


This will now give you access to all of the data of a sprite object and all other inherited classes:

image


Locate and select position, which is a Vector2 object.  Now lets create a variable we are going to use to define our move amount.  In the variables section, click +:

image


Now right click and select Edit Variable:

image


Select type as Vector2 and value of (1,0)

image

Finally click the variable name and rename it to moveBy.  Now drag our newly created variable onto the canvas:

image


Now we want to create an Add node and add our two vectors together, like so:

image


Now we use another Self (or the same one we created earlier) and this time do a Set and select position.  We now pass in the added Vector2 result, also we attach program flow from _process, like so:

image


This simple program will cause the sprite to move by 1 pixel per update.


Video Version

Programming


27. July 2017


Today Godot just released the first downloadable version of the upcoming Godot 3.0 game engine.  This is an alpha level release, so while mostly feature complete do expect to encounter several bugs.  If you are godwaiting for C# support, unfortunately it did  not make it into the alpha release but hopefully will be released soon.  This alpha however is absolutely packed with new functionality including the completely new 3D renderer and material system, a new visual programming language, GDNative, an updated UI and much more.


From the release notes:

The features

Now, there are still some cool features that can already be played with in this alpha1 build, and we are looking forward to seeing what you will come up with using the new 3D renderer. There is no exhaustive listing of all the new features to experiment with, but you can read past articles of this blog and check Juan's Twitter feed for some teasers :)

Please use the community channels to discuss with existing users and learn how to use the new workflows of Godot 3.0 - as of this writing there is almost no documentation on the new features, but this alpha1 build should serve as a starting point for documentation writers.


I made a 20 minute hands-on video showcasing some of the new functionality available in Godot 3.0 available here and embedded below.

GameDev News


5. July 2017


There are a wealth of great add-ons for the Godot game engine, such as Add_Primitives, which adds several geometric primitives to the Godot editor, such as capsules, spheres and more.  This quick tutorial (including a video) goes step by step through the process of enabling an add-on in your Godot project.


First, you need to download the add-on you wish to enable, that or git clone it.  In this tutorial we are going to simply download it.  This link will download the add_primitives add-on zip.


Next, create a project.  Add-on’s are now located at the project level, not in the %APPDATA% folder.  In the project directory, create a folder called Addons.  In that folder, extract the zip file you downloaded earlier.  Next be sure to rename it from add_primitives-master to add_primitives, so the folder name matches the add-on name.  If you cloned using git, you wont have to perform this step.


Now load Godot.  Select the Scene Menu->Project Settings.

image


Switch to the Plugins tab

image


Next change Status to Active.

image


And done!  If you are using the Add_Primitives add-on from this example, you should now see an additional icon in the 3D view:

image


The Add-on will also be shown in your project view:

image


You can watch the above process in video form below.

Programming


15. November 2016

 

First off, I apologize for the pun, I felt obligated to make it.  In a nutshell, Godot 2.2 won’t be happening, so stop waiting for it.  Don’t worry though, it’s for a good reason.  They just posted a status update on Godot game engine development and they have decided to skip the planned Godot 2.2 release and instead focus on Godot 3.0 development. 

In a nutshell, Godot 3.0 is going to have some pretty major low level changes (including new renderers) that would result in a great deal of the features expected as part of 2.2 to require reworking.  So instead these features will be delayed until after the release of 3.0.  So, what features were included in 2.2?  The marque features were C# support, Visual Scripting and the rudiments of networking support.  Don’t worry however, these features are still coming, simply delayed.

The main motivation for changing the roadmap is to release Godot 3.0 sooner. Within the Godot development team, our priority is always to work on what the community needs most at a given point in time - for the past year and a half, the focus has been on greatly improving the usability of the editor, as well as enhancing the 2D tools. Nowadays, Godot is a great engine for making 2D games, and the interest of the growing community is starting to move on to 3D, with corresponding needs for improvements.

For more than a year, Godot 3.0 has been promised to our users as the version that will bring a new state-of-the-art 3D renderer (albeit compatible with a wide range of graphics drivers, hence our choice for GLES 3.0 instead of Vulkan for the time being), and solve many issues and requests users have formulated regarding the current 3D renderer in Godot 2.1.

By skipping the 2.2 release, we allow ourselves (and mostly Juan, our renderer expert) to avoid a lengthy bug fixing and stabilization period on 2.x features. We are therefore aiming for a release of Godot 3.0 in early 2017, which would not have been possible if we had to focus on 2.2 right now.

 

Frankly I agree with this approach.  Most of the features of 2.2 are “nice to have”, while the functionality of 3.0 is more in the “need to have” category.  Fortunately there is some good news as well.  We should expect the 3.0 release to happen faster.  Lead developer Juan Linietsky has been hired full time for 6 months to work directly on Godot thanks to a Mozilla grant:

Last but not least, you might know that we were awarded a hefty sum by Mozilla as part of its MOSS Mission Partners program. This award was aimed at helping us improve Godot's HTML5 export by implementing the brand new WebGL 2.0 and WebAssembly technologies. As the former is basically the same API as GLES 3.0, it's best for us to work on both of them at the same time, so that we can ensure that GLES 3.0 / GL 3.3 and WebGL 2.0 will behave similarly.

Therefore, we decided, together with our non-profit home Software Freedom Conservancy to hire Juan Linietsky full-time for 6 months to work on the objectives funded by the MOSS award. This encompasses in particular the new renderer that will be done for 3.0, and extensive work on the HTML5 platform that might be done partly for 3.0 and in full for 3.1. As Juan is the project leader and our more prolific contributor, this will enable Godot to grow even faster than it has over the last couple of years.

 

Considering how much this guy has managed to accomplish when *not* dedicated to development, just imagine what he can do focused full time?

 

One last piece of bad but somewhat expected information in this update… Godot 3.0 wont be perfectly backward compatible with Godot 2.x and earlier.  I’ve always been pretty impressed with how well they’ve managed to support backward compatibility till this point.  Some of the underlying changes are unfortunately going to break compatibility.  Thankfully they will be providing tools to mitigate this as much as possible:

The new 3D renderer is the opportunity to do some important refactoring of Godot's internals. We also want to use this opportunity to revamp, homogenize and enhance some parts of the API, to make Godot 3.0 a solid base for the further development of the engine and of Godot games.

What does this mean for users? Moving from Godot 2.x to Godot 3.0 will require porting the existing projects to take into account the API changes and the new way resources will be setup in 3.0.

We will provide tools to help with the conversion as well as extensive documentation, so do not worry. You can continue (or start) using Godot 2.x already, as most of the API and workflow will still stay the same, so 98% of what you are doing in 2.x will still be relevant in 3.0.

 

If you were currently waiting on C# or Visual scripting support, this news might be a bit of a let down.  Over all though, I think everything announced makes a great deal of sense.

GameDev News


GFS On YouTube

See More Tutorials on DevGa.me!

Month List