rollerball: 1 of 2
TRANSCRIPT
![Page 1: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/1.jpg)
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: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/2.jpg)
Agenda
Getting Started
> Creating the Ground> Creating the Player> Materials, Colors & Lighting> 3D Physics & Movement
Controlling the Camera
![Page 3: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/3.jpg)
Getting Started
![Page 4: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/4.jpg)
Create New Project
… you should see a New Project window
When you launch Unity 5…
![Page 5: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/5.jpg)
File New Project…
Click File New Project
If you don’t see a New Project window…
![Page 6: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/6.jpg)
Create Project
Select 3D (not 2D)
Enter the following:• Project name: Rollerball• Location: (any new/empty folder)
Click [Create project]
![Page 7: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/7.jpg)
Choose a Layout
Hint: You can drag the panels (Scene, Game, etc) to different locations.
Click Layout dropdown to selector save
![Page 8: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/8.jpg)
Save Your Scene
Hint: You can also click Ctrl-S on your keyboard.
ClickFile Save Scene
![Page 9: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/9.jpg)
Create “Scenes” SubfolderCreateNew folderbelowAssets folder
Name it“Scenes”
![Page 10: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/10.jpg)
Name Your Scene
, then click [Save]… Name your scene “PlayingField.unity”
Inside“Scenes”Subfolder…
![Page 11: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/11.jpg)
Verify Saved Scene
Verify Saved Scene in Project panel
Verify Scene Name in Title Bar
![Page 12: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/12.jpg)
Creating the Ground
![Page 13: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/13.jpg)
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: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/14.jpg)
Verify Plane in Scene & Hierarchy
![Page 15: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/15.jpg)
Rename Plane to “Ground”
Right-click to rename
Enter “Ground”
![Page 16: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/16.jpg)
Rename Plane to “Ground”
Select “Ground”in Hierarchy
Click gear iconnext to Transformthenclick “Reset”
![Page 17: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/17.jpg)
Verify Ground Position at Origin (0,0,0)
![Page 18: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/18.jpg)
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: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/19.jpg)
Zoom In/Out Within Your Scene
Scroll the mouse wheel over your scene to zoom in/out
![Page 20: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/20.jpg)
Show/Hide Grid in Scene ViewIn the Scene panel, click the Gizmos dropdown to toggle “Show Grid”
![Page 21: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/21.jpg)
Resize the GroundClick on the Scale tool, while the Ground is selected…
… then, drag the handles to resize the ground
![Page 22: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/22.jpg)
Enter Scale ValuesManually enter Scale values in the Ground’s Transform component
Scale: X = 2, Y = 1, Z = 2
![Page 23: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/23.jpg)
Creating the Player
![Page 24: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/24.jpg)
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: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/25.jpg)
Position Sphere on Ground
Position Sphere at X = 0, Y = 0.5, Z = 0
![Page 26: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/26.jpg)
Rename Sphere to “Ball”
![Page 27: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/27.jpg)
Materials, Colors & Lighting
![Page 28: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/28.jpg)
Create New Folder for “Materials”
In the Project panel,click Create dropdown
then, select “Folder”
![Page 29: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/29.jpg)
Create New Folder for “Materials”In Project panel,click Create
then, select “Folder”
Rename it “Materials”
![Page 30: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/30.jpg)
Create New Materials for Ground & BallIn Project panel,
click Create
then, select “Material”
Rename it “GroundMaterial”Repeat for “BallMaterial”
![Page 31: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/31.jpg)
Update Material Colors
For each material...
Update colorin Inspectorwindow
(click white square)
![Page 32: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/32.jpg)
Choose Colors in the Popup
• Red• Green• Blue• Alpha (Transparency)
![Page 33: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/33.jpg)
Verify Colors
Verify that GroundMaterial and BallMaterial have different colors.
![Page 34: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/34.jpg)
Assign Colors
Drag each material from Project panel to the Scene panel
![Page 35: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/35.jpg)
Update Lighting Rotation
Update Direction Light in InspectorRotation: X = 50, Y = 60, Z = 0
![Page 36: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/36.jpg)
3D Physics & Movement
![Page 37: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/37.jpg)
Add RigidBodyWith “Ball” selected in the Hierarchy panel…
Click Component Physics RigidBody
![Page 38: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/38.jpg)
(Alternate Method) Add RigidBody
With “Ball” selected in the Hierarchy panel, click Add Component Physics Rigidbody
![Page 39: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/39.jpg)
Verify RigidBody Component for Ball
Verify RigidBody Component
![Page 40: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/40.jpg)
Create New Folder for “Scripts”In the Project panel,click Create dropdown
Then select “Folder”, name it “Scripts”
![Page 41: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/41.jpg)
Create “PlayerController” ScriptIn the Project panel,click Create dropdown Then select “C# Script”, name it
PlayerController
![Page 42: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/42.jpg)
Assign “PlayerController” to Ball
With “Ball”selected...
… Dragscript intoBall
Verify Script Component!
![Page 43: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/43.jpg)
Launch “PlayerController” Script
![Page 44: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/44.jpg)
Get User Input
Add FixedUpdate() method
… just before last curly brace
![Page 45: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/45.jpg)
Calculate 3D Movement
Inside FixedUpdate() method…
Calculate 3D movement
![Page 46: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/46.jpg)
Add RigidBody Force
Define rbjust before Start()
Initialize inside Start() method
Add Force insideFixedUpdate()
![Page 47: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/47.jpg)
Run the Game… too slow?Click Play button, move around with arrow keys!
![Page 48: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/48.jpg)
Add Variable for Speed
Define publicspeed variable
Multiply speedwith movement
![Page 49: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/49.jpg)
Assign Speed in Unity
With “Ball”selected...
Set Speed = 10
What happens if
you set it to 100?
![Page 50: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/50.jpg)
Run the Game… better now?Click Play button, move around with arrow keys!
![Page 51: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/51.jpg)
Controlling the Camera
![Page 52: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/52.jpg)
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: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/53.jpg)
Verify Camera View in Game
Camera should appear higherwith a better view
![Page 54: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/54.jpg)
Create “CameraController” ScriptIn the Project panel,click Create dropdown Then select “C# Script”, name it
CameraController
![Page 55: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/55.jpg)
Launch Script for “CameraController”
![Page 56: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/56.jpg)
Define Instance Variables
Define instancevariablesjust before Start()
![Page 57: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/57.jpg)
Initialize Camera-Player Offset
Initialize offsetin Start() method
![Page 58: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/58.jpg)
Set Camera Position in LateUpdate()
Add LateUpdate()method
Then, setcameraposition
![Page 59: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/59.jpg)
Assign “CameraController” to Camera
With “Main Camera”selected...
… Dragscript intocamera
Verify Script Component!
![Page 60: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/60.jpg)
Assign “CameraController” to CameraWith “Main Camera”selected...
… Drag Ball into Camera’s Player object
![Page 61: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/61.jpg)
Run the Game! Click Play, move around!
![Page 62: Rollerball: 1 of 2](https://reader036.vdocuments.us/reader036/viewer/2022081513/55b6cfc8bb61eb286c8b4964/html5/thumbnails/62.jpg)
End of Part 1