Presentation is loading. Please wait.

Presentation is loading. Please wait.

GameCamp! and Game Davis Creating a 2D Platformer in Unity.

Similar presentations


Presentation on theme: "GameCamp! and Game Davis Creating a 2D Platformer in Unity."— Presentation transcript:

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

2 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.

3 Unity® Interface

4 Create the Player Drag 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 ►Transform Set 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.

5 Create the Player You should now see something like this

6 Give the Player Physics Add a circle collider to Player ▼Player Inspector ►Add Component ►Physics 2D ►Circle Collider 2D

7 Give the Player Physics Add a rigid body component to Player ▼Player Inspector ►Add Component ►Physics 2D ►Rigidbody 2D In 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.

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

9 Test the Game If 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.

10 Add a Wall Prefab Drag 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”

11 Add a Wall Prefab Reset Wall’s transform ▼Wall inspector ►Transform Set position to 0, 0, 0 Set Wall’s color to black (or any color you wish) ▼Wall inspector ►Sprite Renderer ►Color

12 Add a Wall Prefab Scale Wall to 100x100 ▼Wall inspector ►Transform Set scale to 100, 100, 1 Add a box collider to wall ▼Wall Inspector ►Add Component ►Physics 2D ►Box Collider 2D

13 Add a Wall Prefab Drag 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.

14 Create a Floor Drag 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

15 Add a Player Controller Drag 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.

16 Test the Game WASD and Space to control the player

17 Add Crates Let’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

18 Add Crates

19 Make Camera Follow Player We 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.

20 Adjust the Camera This 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.

21 Create a Launcher Plate Drag Pixel into Hierarchy View Rename 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

22 Create a Launcher Add Box Collider Add Surface Effector 2D Select the “Used by Effector” in Box Collider Create Prefab from this

23 Create a Launcher Make wider Launcher (Scale X to 500) Set Speed to 50? 500? -100?

24 Create Water from Pixel Box Collider Area Effector 2D Select “Used by Effetor” Select “Is Trigger” Set Force Direction to 90 Set Force Magnitude to 50, then -100

25 Invisible Water is Air? Check off Sprite-Renderer

26 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!**


Download ppt "GameCamp! and Game Davis Creating a 2D Platformer in Unity."

Similar presentations


Ads by Google