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 , ,

15. September 2017


Some time back Microsoft launched the UWP, Universal Windows Platform, a target enabling you to create Windows store apps that could also be run on XBox One hardware.  There was however a big catch, limited resources.  From the UWP documentation:

  • The maximum memory available to an app running in the foreground is 1 GB.

    • The maximum memory available to an app running in the background is 128 MB.
    • Apps that exceed these memory requirements will encounter memory allocation failures. For more information about monitoring memory use, see the MemoryManager class reference.

  • Share of 2-4 CPU cores depending on the number of apps and games running on the system.

  • Share of 45% of the GPU depending on the number of apps and games running on the system.

  • UWP on Xbox One supports DirectX 11 Feature Level 10. DirectX 12 is not supported at this time.

  • All apps must target the x64 architecture in order to be developed or submitted to the store for Xbox.

So, basically you got access to half of an Xbox One…  Bummer.  Thankfully in the upcoming Fall Update, that is all about to change!  From the Microsoft blog:

Since the advent of consoles, developers have asked for ways to create games for one platform that you could run anywhere. With the release of the Expanded Resources feature in the Windows Fall Creators Update, we are taking the industry closer to that goal than it has ever been before. Now, developers will automatically have access to 6 exclusive cores, 5 GB of ram and full access to the GPU!

Awesome!  I have a video discussing this change available here.

GameDev News

14. September 2017


The Defold Engine just got it’s own community hub, available at defold.com/community.  In addition to the existing forums and social media pages, the community portal now includes an asset portal and a community games showcase.

image

The Asset portal currently contains just under 30 different projects including new project templates, to Unity Ad plugins and UI systems.  The system also enables authenticated users to upload their own assets.  The new Games page showcases games made using the Defold game engine and also includes the ability to upload your own titles.  The look is very polished, although the icons used right now are rather large requiring a fair bit of scrolling.  Hopefully as the site gets more populated, the sizes are dialed back a little bit for efficiencies sake.


Defold is a free 2D Lua powered game engine.  If you are interested in learning more, we have a complete tutorial series available here.

GameDev News

13. September 2017


The Xenko game engine just released version 2.1.  This recently out of beta C# powered game engine just got a bunch prettier with several xenkorendering improvements.  The engine also gained the ability to stream textures which should decrease scene load times and memory usage.  The input system was rewritten and Direct X 12 support was improved.


The following is a summary of new features in the 2.1 release:

  • Local reflections
  • Clear coat shading
  • Thin glass materials
  • Texture streaming
  • Render masks
  • Improved profiler
  • Debug text during runtime
  • Rewritten input system
  • Improved Direct3D 12 support
  • Improved environment fresnel
  • Japanese documentation now available


For more details be sure to check out the release notes which includes a full change log.


Xenko was previously known as Paradox and we did a short tutorial series available here if you wish to learn more.

GameDev News

13. September 2017


Today the Blender Foundation announced the release of Blender 2.79.  Other than a load of bug fixes, there isn’t actually a ton in the releaseB279 directly for game developers.  Perhaps the biggest feature is the new PBR shader node, implemented as the Principled BSDF node based on Disney’s PBR implementation in Renderman.  Other new features include Denoise is a new feature for removing rendering noise, a new Filmic view transform has been added for more photorealistic rendering results, improved OpenCL performance as well as various Cycles renderer improvements.  The Grease pencil also received several improvements in this release including per layer onion skinning and new interpolation tools. 

Perhaps the single best improvement of this release to me personally is automatic DPI scaling.  This means Blender will automatically detect if you are using a high DPI monitor and adjust it’s UI accordingly.  No more having to manually change the user interface each time you plug in an external monitor!


The 2.79 release also includes a ton of new add-ons, including:

Dynamic Sky, Archipack, Magic UV, Mesh Edit Tools, Skinify, Display Tools, Brush Menus, Btrace, Is Key Free, Turnaround Camera, Auto Mirror, Camera Rigs, Snap Utils Line, Add Advanced Objects, Export Paper Model, Kinoraw Tools, Stored Views, Render Clay, Auto Tracker, Refine Tracking Solution, Materials Library VX, Mesh Tissue, Cell Fracture Crack It

Be warned however, there was a change to the way add-ons work with data, meaning that backward .blend compatibility may be impacted!


To read more details of this release check the full release announcement available here.  If you are interested in learning Blender, we have a ton of great tutorials available here.

GameDev News

Month List

Popular Comments