NME17AP
Lukuvuosi 2017-2018
We're going to need Playmaker and Unity for this assignment. Install Playmaker by double clicking the package and choose import. After that open the install folder and install Playmaker.
You can open the Playmaker window from the top by clicking Playmaker and choosing the Playmaker editor. After that you can dock your Playmaker window where ever you want.
Lets start by adding two sprites to the project. One sprite will be the character in the game and the other one is a platform to walk on. Remember to set the texture type of the sprite as 2D & UI. Choose trilinear as the filter mode. Texture mode determines the quality of the sprite and trilinear is the best quality option. Downside for that is that it uses more memory than other modes. It's important to consider the mode especially when making mobile games so that your game is optimized.
After that you can drag and drop your sprites to the scene. You can drag them either to hierarchy window or straight to the scene window. Both methods will work. Select the character sprite and in the inspector set the order in layer so that the number is bigger than the one of your platform sprite. This will make the character always appear in front of the platform and the feet won't look like they get stuck in it. Move the sprites so that they appear in the bottom of the camera view. Add 2D box colliders for both sprites and for the character sprite you're also going to need a rigidbody 2D component. Last thing you need to add for both sprites is a tag. There is a built in player tag that you can use for the character but for the platform you'll need to create a new tag.
Choose you character sprite from the hierarchy window. Add FSM (Fine State Machine) to it. Name the FSM as movement. We want the character to be able to move left and right. For this you'll need to add two event from the event tab. Name the events as left and right. Remember to press enter after you have named one event. Right click the state below the start and choose add transition. Select left and right from the list and add them. Create two new states and name those states walking right and walking left.. You can create new state by right clicking on the grey area and choosing the add state option. Drag an arrow from the right and left events to the two new states.
Now it's time to create the movement. Select the state in the middle and click open the action browser. Find get key down command from the list of actions. You can also type get key down in the search bar. Select that actions two times because you're going to use two different keys for moving. Select A and D for the buttons and make the A button send event left and the D button send event right. Add three actions to the walking right state: get key up, translate and set scale. Get key up determines when the player stops pressing the movement button and it will stop the character movement. Translate will move the character at certain speed on x, y or z axis. Set scale will scale the character so that it will face right when D button is pressed and left when A button is pressed.
Then create new FSM for jumping. Create a new state called jumping and name the first state as idle. The first state has get key down action. Select space as the key. Create a new event called jump and drag an arrow from it to the jumping state. Select Finished as the transition in the jumping state and drag an arrow from it to the idle state. Select add force 2D action for the jumping state. It will add force to the sprite in the selected axis and make it move. Choose y axis and add 300 as the force. Now you character will be able to jump.
Next we are going to do the ground detection by using collision. Create a new state called ground_check in the Jump FSM. Also make new event called collision. Choose collision 2D event action from the action browser and use ground as the collide tag. Make transition from the ground_check state to the start state. Now character won't be able to jump unless it is touching the ground.
Ei kommentteja:
Lähetä kommentti