Derived from Kirill Muzykov’s Rocket Mouse Tutorial WakeUpAndCode.com
Select “Run” Sprite
(Sprite Editor pops up!)
1. Click Slice dropdown 2. Set Type to “Grid” 3. Set Pixel Size X = 156 Y = Click Slice button
Click “Apply” then, close popup
Separate sprites for each frame
Click on Animation tab
Right-click Assets, click Create FolderName it “Animations”
Select “Cat”
In Animation tab, Click dropdown… Create New Clip (twice) run fly
Save “run.anim“Save “fly.anim“
Verify: Cat animation fly clip run clip
Select “Cat” Verify “Animator”
Click “run” animation in dropdown
Expand “Run” animation in “Sprites” folder
Click first frame, press Shift on your keyboard, click last frame
Drag frames into “run” animation
Click “fly” animation in dropdown
Expand “Fly” animation in “Sprites” folder (notice that there’s only 1 frame)
Click Fly frame
Drag frame into “fly” animation
Click “red dot” recording icon to stop recording animations (or just Save)
The cat runs like crazy!!! Run
Update “Sample” to 8
Uncheck Apply Root Motion Change Update Mode to “Animate Physics”
The cat runs slower now, but is still running in the air! Run
Click on Animator tab
Right-click “run” animation, then click “Make Transition”
Click “fly” animation to finish creating the transition
Now, right-click “fly” animation, then click “Make Transition”
Click “run” animation to finish creating the transition
Click + next to Parameters (lower left of Animator tab) Choose “Bool” (which is of type Boolean) Name it “grounded”
Select run fly animation Select “grounded” under Conditions Set to “false”
Select fly run animation Select “grounded” under Conditions Set to “true”
Optional: Check/uncheck “grounded”, then play the game to test the animations Run
Verify new Game Object
Drag GameObject into “Cat”, verify that it is a child of “Cat”, rename to “GroundCheck”
Set Transform Position for “groundCheck” X = 0 Y = -0.7 Z = 0
Click icon symbol to select a color, e.g. green
Verify “groundCheck” game object
Expand “mount1” prefab, select “Floor”
In Inspector panel, click Layer dropdown to Add Layer…
Enter “Ground” for User Layer 8
Update Layer to “Ground”
Add 4 instance variables before Start() method
Add 1 line of code inside Start() method
Add new method UpdateGroundedStatus … just before class ends at the bottom
Add 1 line of code … just before FixedUpdate() ends
Select cat in Hierarchy Verify 2 new public items under Cat Controller script
With Cat selected… Drag “groundCheck” into Ground Check Transform
With Cat selected… set Ground Check Layer Mask to “Ground”
Add 1 line of code just before Start() method
Add new method AdjustJetpack() … just before class ends at the bottom
Add 1 line of code … just before FixedUpdate() ends
With Cat selected… drag “jetpackFlames” into Jetpack
Run The cat should run only while on the ground The jetpack particles should only be visible while in the air