based on roll-a-ball video tutorial from unity technologies part 1 @shahedc wakeupandcode.com

62
By Shahed Chowdhuri Senior Technical Evangelist Unity 5: Rollerball (Step by Step) Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Upload: rudolph-atkinson

Post on 22-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

By Shahed ChowdhuriSenior Technical Evangelist

Unity 5: Rollerball (Step by Step)Based on Roll-a-ball video tutorial from Unity Technologies Part 1

@shahedC

WakeUpAndCode.com

Page 2: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Agenda

Getting Started

> Creating the Ground> Creating the Player> Materials, Colors & Lighting> 3D Physics & Movement

Controlling the Camera

Page 3: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Getting Started

Page 4: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create New Project

… you should see a New Project window

When you launch Unity 5…

Page 5: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

File New Project…

Click File New Project

If you don’t see a New Project window…

Page 6: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create Project

Select 3D (not 2D)

Enter the following:• Project name: Rollerball• Location: (any new/empty folder)

Click [Create project]

Page 7: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Choose a Layout

Hint: You can drag the panels (Scene, Game, etc) to different locations.

Click Layout dropdown to selector save

Page 8: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Save Your Scene

Hint: You can also click Ctrl-S on your keyboard.

ClickFile Save Scene

Page 9: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create “Scenes” SubfolderCreateNew folderbelowAssets folder

Name it“Scenes”

Page 10: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Name Your Scene

, then click [Save]… Name your scene “PlayingField.unity”

Inside“Scenes”Subfolder…

Page 11: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify Saved Scene

Verify Saved Scene in Project panel

Verify Scene Name in Title Bar

Page 12: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Creating the Ground

Page 13: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create a Plane in 3D

Click GameObject 3D Object Plane Click Create 3D Object Plane

In the top menu… In the Hierarchy panel…- OR -

Page 14: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify Plane in Scene & Hierarchy

Page 15: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Rename Plane to “Ground”

Right-click to rename

Enter “Ground”

Page 16: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Rename Plane to “Ground”

Select “Ground”in Hierarchy

Click gear iconnext to Transformthenclick “Reset”

Page 17: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify Ground Position at Origin (0,0,0)

Page 18: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Focus on Ground in SceneWith “Ground” selected in hierarchy…

… press ‘F’ on your keyboard to focus on it

… move your cursor to the Scene

Page 19: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Zoom In/Out Within Your Scene

Scroll the mouse wheel over your scene to zoom in/out

Page 20: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Show/Hide Grid in Scene ViewIn the Scene panel, click the Gizmos dropdown to toggle “Show Grid”

Page 21: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Resize the GroundClick on the Scale tool, while the Ground is selected…

… then, drag the handles to resize the ground

Page 22: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Enter Scale ValuesManually enter Scale values in the Ground’s Transform component

Scale: X = 2, Y = 1, Z = 2

Page 23: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Creating the Player

Page 24: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create a Sphere in 3D

Click GameObject 3D Object Sphere Click Create 3D Object Sphere

In the top menu… In the Hierarchy panel…- OR -

Page 25: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Position Sphere on Ground

Position Sphere at X = 0, Y = 0.5, Z = 0

Page 26: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Rename Sphere to “Ball”

Page 27: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Materials, Colors & Lighting

Page 28: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create New Folder for “Materials”

In the Project panel,click Create dropdown

then, select “Folder”

Page 29: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create New Folder for “Materials”In Project panel,click Create

then, select “Folder”

Rename it “Materials”

Page 30: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create New Materials for Ground & BallIn Project panel,

click Create

then, select “Material”

Rename it “GroundMaterial”Repeat for “BallMaterial”

Page 31: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Update Material Colors

For each material...

Update colorin Inspectorwindow

(click white square)

Page 32: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Choose Colors in the Popup

• Red• Green• Blue• Alpha (Transparency)

Page 33: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify Colors

Verify that GroundMaterial and BallMaterial have different colors.

Page 34: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Assign Colors

Drag each material from Project panel to the Scene panel

Page 35: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Update Lighting Rotation

Update Direction Light in InspectorRotation: X = 50, Y = 60, Z = 0

Page 36: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

3D Physics & Movement

Page 37: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Add RigidBodyWith “Ball” selected in the Hierarchy panel…

Click Component Physics RigidBody

Page 38: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

(Alternate Method) Add RigidBody

With “Ball” selected in the Hierarchy panel, click Add Component Physics Rigidbody

Page 39: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify RigidBody Component for Ball

Verify RigidBody Component

Page 40: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create New Folder for “Scripts”In the Project panel,click Create dropdown

Then select “Folder”, name it “Scripts”

Page 41: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create “PlayerController” ScriptIn the Project panel,click Create dropdown Then select “C# Script”, name it

PlayerController

Page 42: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Assign “PlayerController” to Ball

With “Ball”selected...

… Dragscript intoBall

Verify Script Component!

Page 43: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Launch “PlayerController” Script

Page 44: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Get User Input

Add FixedUpdate() method

… just before last curly brace

Page 45: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Calculate 3D Movement

Inside FixedUpdate() method…

Calculate 3D movement

Page 46: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Add RigidBody Force

Define rbjust before Start()

Initialize inside Start() method

Add Force insideFixedUpdate()

Page 47: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Run the Game… too slow?Click Play button, move around with arrow keys!

Page 48: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Add Variable for Speed

Define publicspeed variable

Multiply speedwith movement

Page 49: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Assign Speed in Unity

With “Ball”selected...

Set Speed = 10

What happens if

you set it to 100?

Page 50: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Run the Game… better now?Click Play button, move around with arrow keys!

Page 51: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Controlling the Camera

Page 52: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Set Camera Position & Rotation

Set Camera Position and Rotation

• Position: X = 0, Y = 10, Z = -10• Rotation: X = 45, Y = 0, Z = 0

Page 53: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Verify Camera View in Game

Camera should appear higherwith a better view

Page 54: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Create “CameraController” ScriptIn the Project panel,click Create dropdown Then select “C# Script”, name it

CameraController

Page 55: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Launch Script for “CameraController”

Page 56: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Define Instance Variables

Define instancevariablesjust before Start()

Page 57: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Initialize Camera-Player Offset

Initialize offsetin Start() method

Page 58: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Set Camera Position in LateUpdate()

Add LateUpdate()method

Then, setcameraposition

Page 59: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Assign “CameraController” to Camera

With “Main Camera”selected...

… Dragscript intocamera

Verify Script Component!

Page 60: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Assign “CameraController” to CameraWith “Main Camera”selected...

… Drag Ball into Camera’s Player object

Page 61: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

Run the Game! Click Play, move around!

Page 62: Based on Roll-a-ball video tutorial from Unity Technologies Part 1 @shahedC WakeUpAndCode.com

End of Part 1