gamecamp! and game dev @ davis creating a 2d platformer in unity

26
GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Upload: raymond-derek-parks

Post on 19-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

GameCamp! andGame Dev @ DavisCreating a 2D Platformer in Unity

Page 2: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Download and Open Project

http://tinyurl.com/2dplatformerbase

This has a few folders containing sprites and scripts to get the game running. I encourage you to take a look at the scripts to understand how they work, and if you have any questions, feel free to ask.

Page 3: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Unity® Interface

Page 4: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create the PlayerDrag and drop the character sprite from the project view (/Sprites/character-sprite) to the scene or hierarchy view.Rename newly placed object in hierarchy to “Player”Reset Player’s transform▼Player inspector

►TransformSet position to 0, 0, 0

To reset an object’s transform, you can also click on the gear icon at the top-right side of the Transform window and select “Reset”. This can be done with any component.

Page 5: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create the PlayerYou should now see something like this

Page 6: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Give the Player Physics

Add a circle collider to Player▼Player Inspector

►Add Component►Physics 2D

►Circle Collider 2D

Page 7: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Give the Player Physics

Add a rigid body component to Player▼Player Inspector

►Add Component►Physics 2D

►Rigidbody 2DIn the Rigidbody 2D component, set Linear Drag to 1, so that the player comes to a stop instead of rolling forever.In the Rigidbody 2D component, set Gravity Scale to 5, so that the player will fall more rapidly and be easier to control.

Page 8: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

2D CameraShow that 2D Unity is flattened 3D by clicking on and off the 2D mode button in the top of the Scene View

Page 9: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Test the GameIf the game is played now, the Player will fall down and off the screen.

We need to create a prefab to act as any static object which the player will collide with, including the floor, walls and any static obstacles.

Page 10: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add a Wall PrefabDrag and drop the “pixel” sprite from the project view (/Sprites/pixel) to the scene or hierarchy view.

Rename newly placed object in hierarchy to “Wall”

Page 11: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add a Wall PrefabReset Wall’s transform▼Wall inspector

►TransformSet position to 0, 0, 0

Set Wall’s color to black (or any color you wish)▼Wall inspector

►Sprite Renderer►Color

Page 12: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add a Wall PrefabScale Wall to 100x100▼Wall inspector

►TransformSet scale to 100, 100, 1

Add a box collider to wall▼Wall Inspector

►Add Component►Physics 2D

►Box Collider 2D

Page 13: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add a Wall PrefabDrag the Wall from the Hierarchy View to the Project View in /Prefabs/

You may delete the Wall in the Hierarchy View, since we have our prefab now.

Page 14: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create a FloorDrag the Wall prefab (in /Prefabs/) into the Scene View somewhere just below the Player

(I set its transform to (0, -2, 0)).

Scale it along the X-axis to something excessive like 10000

Page 15: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add a Player ControllerDrag the PlayerController script from the Project View (/Scripts/PlayerController/) onto the Player object.

Feel free to modify any public values on the script to tweak player movement.

Page 16: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Test the Game

WASD and Space to control the player

Page 17: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add CratesLet’s make it a little more interesting by adding some crates to knock around.I won’t explain exactly how to do this, since you know how to make prefabs and know how to make rigid bodies, but here are the general steps to follow:● Drag into the scene the crate sprite (/Sprites/crate-sprite/)● Add a Rigidbody 2D component● Add a Box Collider 2D● Drag it back into the project view to make it a prefab● Drag that prefab into the scene as many times as you like

Page 18: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Add Crates

Page 19: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Make Camera Follow PlayerWe don’t want the player going off-screen, so we’ll add a smooth camera follow script to the camera and set the player as the target.

Drag the 2DCameraFollow script from the Project View (/Scripts/2DCameraFollow/) onto the Main Camera object.

Under the 2DCamera Follow component of the Main Camera, set Target to Player.

Adjust Damp Time as necessary in order to make the camera follow the player more or less smoothly.

Page 20: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Adjust the CameraThis blue background looks pretty bad, and it’s handled by the camera. Click on the Main Camera, and under the Camera component, change the background color to whatever you like.

While you’re here, feel free to change the camera “Size” to a lower number if you’re having trouble seeing the beautiful pixel art.

Page 21: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create a Launcher PlateDrag Pixel into Hierarchy ViewRename to Launcher

▼Launcher inspector►Transform

Scale: 100, 10, 0

Set Launcher’s color to red (or any color you wish)▼Launcher inspector

►Sprite Renderer►Color

Page 22: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create a LauncherAdd Box ColliderAdd Surface Effector 2D

Select the “Used by Effector” in Box Collider

Create Prefab from this

Page 23: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create a LauncherMake wider Launcher (Scale X to 500)

Set Speed to 50? 500? -100?

Page 24: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Create Water from PixelBox ColliderArea Effector 2DSelect “Used by Effetor”Select “Is Trigger”

Set Force Direction to 90Set Force Magnitude to 50, then -100

Page 25: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Invisible Water is Air?Check off Sprite-Renderer

Page 26: GameCamp! and Game Dev @ Davis Creating a 2D Platformer in Unity

Challenges● Add platforms, ramps, loopty loops and anything else you

can think of● Create a material that when the player touches it, the player

dies● Make crates float in that material● Allow the player to shoot projectiles!● Artists: create sprites to represent any kind of object (can use

Aseprite, Photoshop, MS Paint, make8bitart.com, etc)● **Look at the scripts supplied!**