tiistai 16. elokuuta 2016

Unity platformer - Death zone and collectibles

NAV15AP

1. Jakso lukuvuonna 2016-17

This time we are going to learn how to create death zone and pick up collectibles.

At first we need to create empty game object from top gameobject menu. The object should be placed underneath the floor. Character dies if it drops below the walking platform. We need to add box collider 2D for the empty game object. Be sure that the collider is wide enough that when the character falls, it makes contact with the death zone. Then we are going check the is trigger box in collider window. This enables the use of trigger action in playmaker and makes the collider transparent so that character will not stop when hitting it.





Then it’s time to add FSM to the death zone. Start state will be idle and has an action trigger 2D event in it. When character hits the trigger event is sent to the next state. In the next state we are going to use set position action to set character back to the position it started. Put the start values in the x,y and z axes. When you test the game, the character should move back to the start position when it makes contact with the death zone.


We also want to count deaths. This is done with int add action. You need to make a new variable to use it in int add. There are two different kinds of variables for playmaker: local and global. Local variable is usually available only in the FSM it is designed to. Global variable works across all the scenes and FSM’s in the project. We are going to use the local variable which can be added in the variable tab in this FSM. Be sure to use int as variable type because we only need integer numbers for deaths. In the int add actions we are going to use newly created int variable and add 1 every time the character makes contact with the death zone.



Then we are going to pick up some objects. Draw a simple circle in Photoshop and import it into Unity. Add a circle collider 2D to it and tick the option is trigger. Make FSM for the new object. In the start state we are going to use trigger 2D action. Make a new event for the action and create a new state. In the next state were going to use destroy self action. When player comes in contact with the object it disappears.

ASSIGNMENT 1: Make the player parent object to the camera. This is done by dragging the camera in the hierarchy window under the player so that they are linked. Now you need to figure out how to stop the camera from following the player when it falls to its death. And set the camera back to the starting point when the player respawns. You’ll also need to make the game wait for a while before respawning the player.

ASSIGNMENT 2: Make a global int for the object that is being collected. Use it in the pick up FSM before destroying the object.


Ei kommentteja:

Lähetä kommentti