Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
29. June 2017

Click here for Part One

Creating the Game Scene


Now it’s time to get to work on creating the game itself.  Start off by dragging BowlingLane into the scene.

clip_image002


Now move the lane so it’s at position (0,0,0) in the Inspector under the Transform component.

clip_image004


One thing I noticed is the Normal map is way too strong.  Select the Bowling Lane material (either in the Materials panel, or drill down to it).  Dial back the Normal Map strength from 1.0 to 0.2.

clip_image006


We are almost done with our bowling lane.  The final thing we need to do is add a Collision Shape to it, so the rest of the stuff in our game world will interact with it properly.  With the BowlingLane selected, click Add Component->Physics->Box Collider

clip_image008


The nice thing with Unity is, it will automatically shrink wrap the collider geometry to match your mesh, so you should have to do no additional work!

clip_image010


So, that’s it for the lane, now time to create the Bowling pins.  Simply drag the Bowling Pin into the scene:

clip_image012


Hmmmm… pretty dark. What’s going on here?  Well, right now we are getting our lighting from the Directional Light in our scene.

clip_image014


We don’t want to mess around with advanced lighting, so instead right click and get rid of it. Now lets set up Ambient lighting instead.  Select Window->Lighting->Settings

clip_image016


Change Environment Lighting->Light Source to Color, then select the Ambient Color as white:

clip_image018


Now our scene will have universal consistent lighting:

clip_image020


Now it’s time to add some physics to our pin.  Once again we have to make a collision object component, but we also need to create a RigidBody component.  Add a Box collider just like before.  Then add another Component and select Physics->Rigidbody

clip_image022

The default settings are about right, so there is nothing else we need to do here.


The final thing we need to do with our pin is apply a tag to it so we can locate it using code later. With the Pin selected, in the Inspector at the top drop down the Tag drop down and select Add Tag…

clip_image024


Click the + Icon, then in the resulting text box enter “Pin” then Save.

clip_image026


Now select the Pin again, and in the Tags list, select Pin which should now be an option.

clip_image028


Now we simply need to create 4 ( or 9… depending your bowling preferences ) clones of our pin. Select the BowlingPin in the scene graph, right click and select Duplicate.  This will create a copy with all of the settings and components defined. 

clip_image030


After duplicating, position the pin and repeat the process until you have enough pins.

clip_image032


Click here to continue to part three.

Programming


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.

clip_image002


Once created, rename it to BowlingBall.

clip_image004

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.

clip_image006

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.

clip_image008


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:

clip_image010

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)
        {
            pinPositions.Add(pin.transform.position);
            pinRotations.Add(pin.transform.rotation);
        }

        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++)
            {
                //collision.gameObject.transform.parent.gameObject.tag
                var pinPhysics = pins[i].GetComponent<Rigidbody>();
                pinPhysics.velocity = Vector3.zero;
                pinPhysics.position = pinPositions[i];
                pinPhysics.rotation = pinRotations[i];
                pinPhysics.velocity = Vector3.zero;
                pinPhysics.angularVelocity = Vector3.zero;

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

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.

clip_image012


And done!


The Video

Programming


26. October 2016

 

Unity Asset Bundles enable you to stream assets over the web and use them at run-time.  The problem is, they are tricky to use, need to be generated for each platform and often required each studio to create a tool to properly make use of them.  Today Unity released a tool aimed at making Asset Bundles easier to create and manage.  Keep in mind the tool is just a prototype so expect some bugs and usability issues.

 

From the announcement blog:

Make AssetBundle workflow visual, more intuitive

An easy to learn and flexible visual tool for creating a build pipeline that can support some of the complexities of real productions, the Asset Bundle graph tool provides a workflow with the following features:

  • Create AssetBundles with no coding. Create nodes, connect them and simply press the build button to give you the AssetBundles you desire!
  • Easily understand what happens when you build: which files are targeted, where they go and how they are included in which asset bundle files.
  • Create pipeline in a rule-based model. So once you configure the pipeline and set up simple rules with name and path conventions, you can then completely forget about AssetBundle configurations. Share that rule with your team and just keep creating and adding assets as long as your team is following the conventions. When you press build, those new files are automatically targeted and you will get new AssetBundles accordingly. 

We have come to the point when we’re ready to share this with you. Like many other tools we released recently, we are releasing this tool in open-source, under the MIT license. The tool is still in prototype phase, so we would be delighted if you gave it a try and tell us what you think. You can also freely modify the tool to match your needs, or join in its development.

 

The source code for this new tool is available on Bitbucket.  Yeah, not Github, BitBucket.

GameDev News


26. September 2016

 

Daydream is Google’s project to bring VR to the Android platform.  Two of the biggest game engines, Unity and Unreal, just announced Daydream support in preview forms.image

 

First Unity’s announcement:

We’re excited to announce that native Daydream support is available as of today! It brings a more streamlined workflow, significant optimizations and reduced latency beyond the Google VR SDK for Unity released at Google I/O. No prefabs, scripts or manual manifest modifications are required to get started – simply enable VR and add Daydream as a targeted platform and begin making your own virtual worlds.

Unity’s native support for Daydream aims to solve the hard problems for you. To get optimal performance and latency from the platform we have done a deep integration with the Daydream SDK to leverage the platform’s asynchronous reprojection and VR performance mode. We have also made it easy to switch in and out of VR mode so that your applications can easily expand to the Google VR audience.

Not targeting just Daydream hardware? You can also have your application target Google Cardboard with native support. Applications which target Cardboard will work on older devices so that your application can reach as many users as possible. At this time, Cardboard support is exclusive to Android with iOS Cardboard support coming soon.

You can find more information and download the Technical Preview here. For questions or feedback head over to the new Daydream forum.

Google has also created a Unity SDK which expands Unity further by providing spatialized audio, Daydream controller support, utilities and samples. Please see the script reference and download pages for more details.

 

And now Unreal Engine:

Back in May during Google I/O, Epic announced its day one support of Daydream, Google’s exciting mobile VR platform for high quality, mobile virtual reality which is coming in Fall 2016 and will provide rich, responsive, and immersive experiences with hardware and software built for VR.

Well, after gathering developer feedback and evolving its resources into a suite of powerful tools, Google has announced that Google VR SDK 1.0 has graduated out of beta and is now available on theDaydream developer site

As pointed out in the official announcement post, the updated SDK simplifies common VR development tasks so developers can focus on building immersive, interactive mobile VR applications for Daydream-ready phones and headsets while supporting integrated scanline racing and interactions using the innovative Daydream controller.

With this release, significant improvements to UE4’s native integration have been implemented that will help developers build better production-quality Daydream apps. The latest version introduces Daydream controller support in the editor, a neck model, new rendering optimizations, and much more - many features of which will be rolled directly into Unreal Engine 4.13.1 with the rest being availablenow through GitHub and rolling into 4.14.

Interested in accessing Google Daydream SDK 1.0? UE4 developers can do so right now by downloading the source here. We can’t wait to see what types of content the Unreal Engine community dreams up!

 

As mentioned in the Unreal Engine announcement, Google also released the 1.0 version of their new GoogleVR SDK.

GameDev News


12. September 2016

 

One of the major features announced when Unity added the “Plus” tier was the addition of the Splash screen tool.  This tool would enable Plus and Pro subscribers to remove the Made With Unity splash screen completely, while also allowing greater customization for users the chose to keep the logo.  Basically it breaks down, per tier as:

Plus and Pro subscribers

You will have the choice to:

  • Use the new tools, include the Made with Unity co-branding
  • Use the new tools, and remove the Made with Unity co-branding
  • Remove the splash screen and roll your own solution.

 

While for the free tier:

Personal Edition Users

You’ll have the same splash screen tools as everyone else, but we’ll include the Made With Unity co-branding, positioned either below, or sequentially with your branding design.

For all Unity users, the new splash screen tools now feature a range of easy to configure options: You can choose whether to display a dark or light Made with Unity branding and your company logo on sequential screens or combined on a single screen, and whether to use an image or a solid colour as a background. You also have the option to show several logos on sequential screens, for instance a publisher logo followed by a developer logo. And lastly, you can choose between a static logo or a dolly animation, or opt to define the custom parameters of the logo animation using the Logo Duration, Logo Zoom, and Background Zoom properties.

 

Unity just released a video showing the new tool in action.

 

There are however some known issues with the initial release:

  • We still need to add an API so the splash screen can be configured from script.
  • WebGL: We have some upcoming changes that will show a simplified version of the splash screen immediately and then blend to the new one.
  • STV: There is an issue when drawing the splash screen on Samsung TV, we are working on this and will have a fix before the end of the beta period.
  • VR: The VR splash screen is a placeholder, we have plans to add support for a 3D version during the beta period.

 

You can read more about the splash screen tool release here.  The tool is included in the just released 5.5.0b3 release.

GameDev News


GFS On YouTube

See More Tutorials on DevGa.me!

Month List