Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

29. June 2017

Click here to go back to Part Two.

Next, we need to create a bowling ball.  Instead of importing a 3D mesh, we are going to create one.  Select Game Object->3D Object->Sphere.


Once created, rename it to BowlingBall.


While we are here, create a new Tag called Ball and assign it to our object.

Let’s create a material for our Bowling ball.  Right click assets panel, select Create->Material.  Rename the newly created material BowlingBall.  Pick the color of your bowling ball with the box to the right of Albedo.  For shine add a small amount of Metallic as well.


Now simply drag the newly created material over to our Bowling Ball in the scene.

We also need to attach physics to our bowling ball.  This time it’s using a Sphere Collider.  This is also a rigid body, but this time we increase the mass to 3.


We are going to be putting all of the logic in our bowling ball.  One thing we are going to need to do is play audio when our ball hit’s a pin. We will add this logic later, but the audio source needs to be somewhere, so why not the bowling ball. We actually covered this process earlier when we added audio to our title screen.  Simply add an Audio Source component to the ball then attach the Hit.wav file, like so:


Tick off the Play on Awake checkbox.

Now its time to add some scripting to our game to control input and to deal with physics collisions when they happen. Right click the Assets panel and create a new script like we did earlier. Rename it BowlingBall.cs and drag it onto our BowlingBall object.  Now double click our script and enter the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BowlingBall : MonoBehaviour
    public float force;
    // Use this for initialization
    private List<Vector3> pinPositions;
    private List<Quaternion> pinRotations;
    private Vector3 ballPosition;
    void Start()
        var pins = GameObject.FindGameObjectsWithTag("Pin");
        pinPositions = new List<Vector3>();
        pinRotations = new List<Quaternion>();
        foreach (var pin in pins)

        ballPosition = GameObject.FindGameObjectWithTag("Ball").transform.position;

    // Update is called once per frame
    void Update()
        if (Input.GetKeyUp(KeyCode.Space))
            GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, force));
        if (Input.GetKeyUp(KeyCode.LeftArrow))
            GetComponent<Rigidbody>().AddForce(new Vector3(1, 0, 0), ForceMode.Impulse);
        if (Input.GetKeyUp(KeyCode.RightArrow))
            GetComponent<Rigidbody>().AddForce(new Vector3(-1, 0, 0), ForceMode.Impulse);
        if (Input.GetKeyUp(KeyCode.R))
            var pins = GameObject.FindGameObjectsWithTag("Pin");

            for (int i = 0; i < pins.Length; i++)
                var pinPhysics = pins[i].GetComponent<Rigidbody>();
                pinPhysics.velocity =;
                pinPhysics.position = pinPositions[i];
                pinPhysics.rotation = pinRotations[i];
                pinPhysics.velocity =;
                pinPhysics.angularVelocity =;

                var ball = GameObject.FindGameObjectWithTag("Ball");
                ball.transform.position = ballPosition;
                ball.GetComponent<Rigidbody>().velocity =;
                ball.GetComponent<Rigidbody>().angularVelocity =;
        if (Input.GetKeyUp(KeyCode.B))
            var ball = GameObject.FindGameObjectWithTag("Ball");
            ball.GetComponent<Rigidbody>().velocity =;
            ball.GetComponent<Rigidbody>().angularVelocity =;
            ball.transform.position = ballPosition;
        if (Input.GetKeyUp(KeyCode.Escape))
    private void OnCollisionEnter(Collision collision)
        if (collision.gameObject.tag == "Pin")

We publicly expose the Force value, which is the amount of energy to apply along the Z axis when we throw the ball.  Since it is public, it’s settable in the editor as a property in the script component.


And done!

The Video

Programming , , ,

28. June 2017

During GDC in early 2017, Github released a Unity extension enabling direct Git and Github functionality inside the Unity editor.  Today at Unity’s European developer conference, Github have now announced that this extension is open source.  The extension enables you to also use the Git LFS ( Large File System ) extension, enabling efficient handling of large files that are common in game development.

Perhaps the most important feature of this release is the ability to manage version control directly in the Unity editor ( as shown below ) enabling you to switch between branches, perform commits and push to Github without having to drop to the command line.


The extension is still under development and some known issues still exist, including:

You can read more about the release here  The extension is available on BitBucke.... er... wait no, that’s not right.  Oh yeah, the sources are available on Github here.

GameDev News

27. June 2017

Leadwerks game engine 4.4 was released yesterday  Leadwerks bills itself as the easiest to learn way to build 3D games.  The primary scripting language is Lua, while the professional version has C++ programming as an option.  The 4.4 release adds new GUI support, inverse kinematics, updated post processing effects and more. 

From the release blog:

Leadwerks Software today announced the release of version 4.4 of their topselling game engine on Steam.  This version adds a new GUI system, support for inverse kinematics, and enhanced visuals.  The free update goes out today to over 20,000 paid users on Steam. Screenshots_screenshot259.thumb.jpg.7fe75bab83a6be87c1aa01f197efa93a.jpg

Leadwerks Game Engine 4.4 sees the introduction of Leadwerks GUI, a system for creating resolution-independent in-game menus.  Custom GUI elements can be created with Lua script, or an item can be selected from a number of pre-built GUI scripts including buttons, tabbed panels, slider controls, and more.  Leadwerks GUI is designed for the future, with support for 4K and 8K displays, as well as VR menus of any resolution.

Inverse kinematics are now supported, with two new joints that provide fine control over the orientation of physics bodies.  These can be used to control the end effector in an IK setup, or for precise control of moving objects.  The Leadwerks physics system has been updated to the latest Newton Dynamics 3.14.

Post-processing effects have been updated to enhance visual quality.  Bloom, HDR iris adjustment, SSAO, and fog have all been updated for improved graphics.  A new shader has been added to the vegetation system that scattering millions of rocks across a landscape to make terrain more detailed and realistic.

The Leadwerks learning materials have been converted into an all-new documentation system.  This allows easier searching and browsing of tutorials, API documentation, and examples.  A new series of tutorials has been added to teach the basics of C++ programming, in addition to the existing lessons on Lua scripting.

Leadwerks Game Engine can be purchased at a discount during the Steam summer sale.  All Leadwerks games have Steamworks support integrated out-of-the-box and are ready to publish through Steam Direct.

If you are interested, Leadwerks is currently available as part of the Steam Summer Sale at an 80% discount.

GameDev News

27. June 2017

Defold Engine 1.2.107 has just been released.  The Defold Engine is a Lua powered 2D focused game engine made freely available by King.  If you want to learn more about the Defold Engine, we have a full tutorial series available here.  The 1.2.107 release improves asset pre-loading, texture loading/creation performance and more.

Details from the release notes:


  • DEF-2772 - Added: Async decoding of WebP images
  • DEF-2651 - Added: Async texture GPU upload
  • DEF-2770 - Added: Added LuaSocket documentation
  • DEF-2688 - Fixed: The particle spawn rate spread is now working
  • DEF-2768 - Fixed: Libraries with unusual folder structure crashed Bob
  • DEF-2756 - Fixed: Small improvement on error handling if the generated doesn't compile
  • DEF-2625 - Fixed: Increased buffer used to parse game.project values to 2048


  • We've added a brand new tutorial of how to make a classic 15 puzzle game
  • we've also added documentation for LuaSocket in both editors
  • Lots of smaller fixes

There was also some discussion on features that are currently in the works:

Native Extensions

The work on Windows support is progressing nicely.
The main parts of the build pipeline is functional, with some cleanup left to do.
Planning for a release in the next sprint.

Facebook Gameroom

Another upcoming big feature is support for Facebook's Gameroom.
This will allow you to use Facebook and in app puchases on the Windows platform through their new platform.
This feature is estimated to arrive in the next release.

Particles in GUI

A long awaited feature is support for particles in GUI.
It is a big task with some big refactoring involved, but it is going well.
A recent benefit from this was the batching of particle systems.

One other small part of this release is anonymous usage tracking, something many are surely not going to like.

We have also added anonymous tracking of how the editor is being used* in order for us to better understand our users, help us with prioritisation and improve the product.

(*Clarification edit: it tracks what version is running and what parts of the editor that are used)

People REALLY hate this stuff, myself included, so if it can’t be toggled off, this new feature strikes me as a mistake.

GameDev News

27. June 2017

Starling 2.2 was just released today.  Several new features were added including inverted masks, stronger blurs, binding scale9 grids to texture, async bitmap upload and more.  Starling is an open source game framework for ActionScript (Flash)  offering an easy 2D api with graphics acceleration.  The Starling framework has been used to power several popular games including titles in the Angry Birds series.

Details from the changelogs:

  • added 'DisplayObject.isMaskInverted' (thanks to Ehsan Marufi)
  • added support for stronger blurs with fewer passes to BlurFilter
  • added 'Image.bindScale9GridToTexture' for automated scale9Grid setup (thanks to Kevin Foley)
  • added 'Image.bindPivotPointToTexture' for automated pivot point setup
  • added 'Image.automateSetupForTexture' for automated setup of all the rest ;)
  • added workaround for memory issue on iOS concerning BatchPools
  • added 'padding' to TextField class → allowing injection of 'TextOptions' into TextField
  • added convenience methods and properties to 'Padding' class
  • added 'Painter.setupContextDefaults' and using it in 'DisplayObject.drawToBitmapData'
  • added support for asynchronous bitmap texture uploads (via 'Texture.asyncBitmapUploadEnabled')
  • added support for specifying the alpha value with which the context is cleared each frame
  • added support for overriding 'updateTransformationMatrix' in display objects
  • added methods for quickly checking the current platform in SystemUtil (thanks to Kevin Foley)
  • added 'numSides' parameter in 'Polygon.createEllipse' and 'createCircle' (thanks to Ehsan Marufi)
  • added 'StringUtil.parseBoolean' and using it for XML parsing in TextureAtlas
  • added 'TextureAtlas.addSubTexture' (thanks to Ehsan Marufi)
  • added 'RectangleUtil.extendToWholePixels' and using it to optimize area processed by fragment filter
  • added 'DisplayObject.drawToBitmapData' method
  • added link to new manual to README
  • added iPad support and auto-orientation to scaffold project
  • added 'Field Agent' utility for simple distance field creation
  • added depth test settings to RenderState (thanks to Alexander Mokretsov)
  • added 'styleSheet' property to TextField
  • added color component setter functions to 'Color' class (thanks to Alexander Mokretsov)
  • added 'letterSpacing' property to 'TextFormat' class (thanks to pbalmasov)
  • added 'antiAliasing' property to FragmentFilter
  • changed 'TextField.setRequiresRecomposition' to be public
  • changed that Travis build now always uses the latest AIR SDK
  • changed that Starling now stops with an error if AIR/Flash runtime version is not supported
  • changed 'scaffold_mobile' project to be better suited for current mobile device
  • changed that 'copyFrom' is called before setting the new style in MeshBatch (thanks to Robert Carone)
  • changed IntelliJ IDEA resource utility so it's easier to use
  • changed that 'depthAndStencil' warning is printed out on first use of masks
  • optimized MiniBitmapFont: replaced XML with compressed ByteArray to save space
  • optimized masking: now using depth test to prevent masks from being drawn (thanks to Ehsan Marufi)
  • optimized transformation matrix workflow
  • optimized 'removeEventListener' by avoiding duplicate vector creation (thanks to Josh Tynjala)
  • optimized pushing and popping of state stack in DisplayObjectContainer (thanks to vroad)
  • fixed that objects were not notified if HOVER phase ended due to display list changes
  • fixed possible null reference error in Sprite3D instances
  • fixed that back buffer could be left in unknown state after disabling 'Starling.shareContext'
  • fixed that 'alignPivot' did not force transformation matrix update on Sprite3D
  • fixed that internal 'dispose' was called twice on empty TextField (thanks to 5k0rp)
  • fixed that render context was disposed before the stage (thanks to neuronix)
  • fixed that changing camera settings did not force redraw
  • fixed 'drawToBitmapData' when called on the stage with negative viewPort.x/y
  • fixed that DisplacementMapFilter did not clamp edge pixels
  • fixed that 'copy_resources.rb' script could not handle multiple configurations
  • fixed that helper matrix was not initialized in FragmentFilter (thanks to bwhiting)
  • fixed iPad logic of mobile scaffold
  • fixed that 'Juggler.removeDelayedCalls' didn't remove the id of the delayed call
  • fixed that disposing video texture did not always cut connections to camera and net stream
  • fixed some class references in the API documentation
  • fixed that 'setRequiresRedraw' was not called after resizing native window (thanks to Josh Tynjala)
  • fixed that masking a filtered object with a clipRect did not work
  • fixed exception on rendering of mesh occurring when its style was changed
  • fixed that back buffer sizes below 32x32 lead to an exception (now forcing this minimal size)
  • fixed null pointer exception in Pool.getPoint3D

You can read a great deal more about this release here.  Starling is available for download here.

GameDev News

Month List

Popular Comments