Lukuvuosi 2017-2018
We're going to make hanging mechanics for the character. For this assignment you'll need to have two more animations to your character: hanging idle and movement animations. Also create a platform that has vines below it.
Create your hanging animations and link them in them in the animator window. Create two new bool parameters for idle and moving hanging.
Next add new FSM component for the player. This FSM has four states, two global events: hang & don't hang and three normal events: left, right & drop.
The first state has don't hang as a global transition. It also has four actions. First action is set property in which you'll need to drag and drop the player movement FSM component to target object section. Remember to tick the enabled box. This will make the movement FSM active when player is not hanging.
Second and third actions are both set animator bool. Select your hanging and idle hanging parameters to it and don't click the value box because we want those animations to be inactive in this state.
Last action in this state is set property. Drag the rigidbody 2D component to the target object section and select gravity scale as property and 1 for the value. This makes gravity active when the player is not hanging.
You'll need same four actions as you had in the first state, so copy and paste those from that state to this one. This time the set property for the player movement FSM has no tick in the set value box and gravity scale is set to 0. Also tick the value box for the set animator bool action for idle hanging.
Add three get key down actions. Select key D for the first one and make it send right event. Next select key A and make it send left event. Last get key down action has S as the key and it sends drop event.
Third state is for hanging and moving. In this state you'll need five actions and two events: drop & finished. First action is set animator bool which has the parameter hanging activated. Second event is get key down. In this action choose S as the key and make it send drop event which is linked back to the first state. Third action is get key up. Choose A as the key which sends the finished event back
to the first state. Fourth action is set scale. This is needed when player changes direction. If the player faces right by default then you'll need -1 in the x axis. Last action is translate which is used to move player. Put a number in the x axis section. If player moves left then you'll need to add minus sign before the number.
Last state is similar to the third state. Just change D to the get key up action and don't put negative numbers to set scale and translate actions.
Then create new FSM for the hanging platform. This FSM has three states and two events: activate hanging & deactivate hanging.
First state has trigger 2D event action. Choose player as collide tag and make it send activate hanging event.
Second state has also trigger 2D event action. This time choose on trigger exit 2D for the trigger section, player as collide tag and make it send event deactivate hanging. Second action for this state is send event by name. This send information for the player hanging FSM so that it knows to activate hanging mode. Choose game object FSM for the event target, remember to select specify game object and drag the player object to it. Choose your hanging FSM for the FSM section and select the global hang event to the send event section.
Ei kommentteja:
Lähetä kommentti