derived from kirill muzykov’s rocket mouse tutorial @shahedc wakeupandcode.com

68
By Shahed Chowdhuri Sr. Technical Evangelist Unity 2D: Step by Step, Part 3 Derived from Kirill Muzykov’s Rocket Mouse Tutorial http:// www.raywenderlich.com/69392/make-game-like-jetpack-joyride-unit y-2d-part-1 @shahedC WakeUpAndCode.com

Upload: geoffrey-freeman

Post on 16-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

By Shahed ChowdhuriSr. Technical Evangelist

Unity 2D: Step by Step, Part 3Derived from Kirill Muzykov’s Rocket Mouse Tutorialhttp://www.raywenderlich.com/69392/make-game-like-jetpack-joyride-unity-2d-part-1

@shahedC

WakeUpAndCode.com

Page 2: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Slicing Sprite Sheets

Page 3: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “Run” Sprite in Project panel

Select “Run”Sprite

Page 4: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Set “Sprite Mode” to “Multiple”

Page 5: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Click “Sprite Editor” Button

(Sprite Editor pops up!)

Page 6: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Slice It!1. Click Slice dropdown

2. Set Type to “Grid”

3. Set Pixel Size• X = 156• Y = 156

4. Click Slice button

Page 7: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Apply the Slice Click “Apply”

then, close popup

Page 8: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Verify Run Sprites in Project Panel

Separate spritesfor each frame

Page 9: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Creating Animations

Page 10: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Click Window Animation

Click on Animation tab

Page 11: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create “Animations” Folder

Right-click Assets, click Create Folder Name it “Animations”

Page 12: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “Cat” in Hierarchy

Select “Cat”

Page 13: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create New Animation

In Animation tab,

Click dropdown…

Create New Clip (twice)• run• fly

Page 14: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create Clips for “run” and “fly”

Save “run.anim“ Save “fly.anim“

Page 15: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Verify Animations

Verify:• Cat animation• fly clip• run clip

Page 16: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Verify Animator Component

Select “Cat”

Verify “Animator”

Page 17: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Adding Run Frames

Page 18: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “run” Animation

Click “run” animationin dropdown

Page 19: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Expand “Run” Spritesheet

Expand “Run” animation in “Sprites” folder

Page 20: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “Run” Frames

Click first frame, press Shift on your keyboard, click last frame

Page 21: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Drag “Run” Frames into “run” Animation

Drag frames into “run” animation

Page 22: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Adding Fly Frames

Page 23: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “fly” Animation

Click “fly” animationin dropdown

Page 24: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Expand “Fly” Spritesheet

Expand “Fly” animation in “Sprites” folder(notice that there’s only 1 frame)

Page 25: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select “Fly” Frames

Click Fly frame

Page 26: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Drag “Fly” Frame into “fly” Animation

Drag frame into “fly” animation

Page 27: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Stop Recording Animations

Click “red dot”recording iconto stop recordinganimations

(or just Save)

Page 28: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Run the Game!

The cat runs like crazy!!!

Run

Page 29: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Fixing the Animation

Page 30: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Update “run” Animation Sample Value

Update “Sample” to 8

Page 31: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Update Cat’s Animator Component

Uncheck Apply Root Motion

Change Update Mode to“Animate Physics”

Page 32: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Run the Game!

The cat runs slower now, but is still running in the air!

Run

Page 33: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Creating Transitions

Page 34: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Click Window Animator

Click on Animator tab

Page 35: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create Transition…

Right-click “run” animation, then click “Make Transition”

Page 36: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Complete Transition… From “run” to “fly”

Click “fly” animation to finish creating the transition

Page 37: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create Another Transition

Now, right-click “fly” animation, then click “Make Transition”

Page 38: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Complete Transition… From “fly” to “run”

Click “run” animation to finish creating the transition

Page 39: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add Parameter

Click + next to Parameters (lower left of Animator tab)

Choose “Bool” (which is of type Boolean)Name it “grounded”

Page 40: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Set Parameter Condition For “run” “fly”

Select run fly animation

Select “grounded” under Conditions

Set to “false”

Page 41: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Set Parameter Condition For “fly” “run”

Select fly run animation

Select “grounded” under Conditions

Set to “true”

Page 42: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Run the Game!

Optional: Check/uncheck “grounded”, then play the game to test the animations

Run

Page 43: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Working with the Ground

Page 44: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Create Empty Game Object

Verify new Game Object

Page 45: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Drag GameObject into Cat, Rename It

Drag GameObject into “Cat”, verify that it is a child of “Cat”, rename to “GroundCheck”

Page 46: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Set “groundCheck” Position

Set Transform Position for “groundCheck”• X = 0• Y = -0.7• Z = 0

Page 47: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select Icon and Color

Click icon symbol to select a color, e.g. green

Page 48: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Verify “groundCheck” in Scene

Verify “groundCheck” game object

Page 49: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Select Floor Inside Prefab

Expand “mount1” prefab, select “Floor”

Page 50: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add Layer…

In Inspector panel, click Layer dropdown to Add Layer…

Page 51: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Enter “Ground” Layer

Enter “Ground” for User Layer 8

Page 52: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Assign Floor to “Ground” LayerUpdate Layer to “Ground”

Page 53: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Launch “CatController” Script

Page 54: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add Instance Variables

Add 4 instancevariables beforeStart() method

Page 55: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Initialize Animator

Add 1 line of codeinside Start() method

Page 56: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add New Method to Update StatusAdd new method UpdateGroundedStatus

… just before class ends at the bottom

Page 57: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Call Method to Update Grounded Status

Add 1 line of code

… just before FixedUpdate() ends

Page 58: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Verify New Items

Select cat in Hierarchy

Verify 2 new public items under Cat Controller script

Page 59: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Assign Ground Check Transform

With Cat selected…Drag “groundCheck”into Ground CheckTransform

Page 60: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Assign Ground Check Layer Mask

With Cat selected…set Ground CheckLayer Mask to“Ground”

Page 61: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Toggling the Flames

Page 62: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Launch “CatController” Script

Page 63: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add Public Variable for Jetpack

Add 1 line of codejust before Start() method

Page 64: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Add Method to Adjust Jetpack

Add new method AdjustJetpack()

… just before class ends at the bottom

Page 65: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Call Method to Adjust Jetpack

Add 1 line of code

… just before FixedUpdate() ends

Page 66: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Assign Ground Check Transform

With Cat selected…drag “jetpackFlames”into Jetpack

Page 67: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

Run the Game! Run

• The cat should run only while on the ground• The jetpack particles should only be visible while in the air

Page 68: Derived from Kirill Muzykov’s Rocket Mouse Tutorial  @shahedC WakeUpAndCode.com

End of Part 3