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.

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


7. September 2016

 

One of the biggest challenges that app developers face these days is discoverability.  You can spend all the time and money in the world developing the next great game, but if nobody finds it, nobody will play it.  This new program is aimed at promoting Unity developed games on Samsung’s store.  The catch... your application must be made with Unity and you must agree to at least 90 days of exclusivity with Samsung.

 

So, what does this exclusivity buy you?

  • 4 weeks of banner promotion in the Galaxy Apps stores in US and Canada, targeting 30K installs/month (this is an average and not guaranteed)
  • Collapse within the Top Games category after 4 weeks, continued banner promotion possible based on performance
  • Push notification issued to the Galaxy Apps user base during the exclusivity period
  • Galaxy Gifts carousel inclusion for the duration of the exclusivity
  • Social networks, Samsung Developers website and newsletter promotion
  • Trade show presence

 

If they hit that 30K average installs, it certainly could be a worthwhile program for many.  I am not sure how far their reach actually is.  My personal phone is a Galaxy S6 and I’ve gone to the Samsung store exactly... never.  Perhaps I am the exception, but I don’t think I am.

 

You can read more about the program here.

GameDev News


See More Tutorials on DevGa.me!

Month List