Unity / Playmaker Tutorial - Trigger Animation - Sliding Doors
ฝัง
- เผยแพร่เมื่อ 9 ก.พ. 2025
- This tutorial will show you how to create a simple sliding door animation (legacy) and then trigger it when the player comes close to it in Unity. Some basic aspects of the tutorial are time-lapsed for convenience.
1. Create a new project and new scene in Unity and import the Playmaker package (www.hutonggames... or Asset store)
2. Create a floor and two walls beside each other with a gap in the middle for a door
3. Make sliding doors from two cubes, one half on each side in between the two walls
4. Create an empty object and place it in front of the sliding doors
5. Rename the left side of the door to ‘DoorL’ and the right side to ‘DoorR’
6. Make the two sides of the door children of the empty object. Rename it to ‘DoorParent’
7. Select ‘DoorParent’ and open the ‘Animation’ window
8. Choose ‘Create New Clip’. Rename it to ‘DoorIdle’
9. Click the small arrows and choose ‘Create New Clip’ and rename this one to ‘DoorOpen’. Click ‘Add Property’
10. In the timeline, go to 1 second and drag the right door to the right so it is open
11. Repeat for the left door and you should see the keyframes added automatically in the animation window
12. Click ‘Create New Clip’ again and rename this one to ‘DoorClosed’. Click ‘Add Property’
13. In frame 1, open the doors and at 1 second, have them closed again.
14. In your assets folder you will see the animations that you just created
15. Click on ‘DoorClosed’ and in the Inspector panel, click on the icon in the top right
16. Select ‘Debug’ from the dropdown menu and then make sure the ‘Legacy’ box is checked
17. Repeat this for ‘DoorIdle’ and ‘DoorOpen’, making sure ‘Legacy’ is checked each time
18. Select the ‘DoorParent’ object. In the Inspector panel, remove the ‘Animator’ component
19. Click ‘Add Component’ and choose ‘Physics - Box Collider’. Tick the ‘Is Trigger’ check box
20. Resize and reposition the box collider so that it is in front of your sliding doors
21. Import the Character package and add a First Person Controller to the scene
22. Select the ‘DoorParent’ object and add a new FSM in Playmaker
23. Add a ‘TriggerEnter’ transition to state1. Add a new state and add a ‘TriggerExit’ transition
24. Add one more state and add a ‘Finished’ transition. Connect State1 to 2 and 2 to 3 and 3 back to 1 again.
25. Test the game to see if the trigger is working. Make sure your doors are not touching anything else or the state will automatically trigger to State 2. Move to the door to test.
25. Select State 2 and add a ‘Play Animation’ action from the Playmaker Actions panel
26. You will notice a warning ‘GameObject requires Animation component!’ Click the warning.
27. Go to the Inspector and look at the ‘Animation’ component that has been added
28. In the ‘Animation’ field, drag the ‘DoorIdle’ animation from the Assets panel
29. Change ‘Animations - Size’ to 3. Change Element1 to DoorOpen and 2 to DoorClosed
30. Make sure the ‘Play Automatically’ box is unchecked or else the animation will just start playing by itself
31. Select State2 and go back to the ‘Play Animation’ action in the Playmaker editor window.
32. Beside ‘Anim Name’ use the drop down menu icon to select ‘DoorOpen’
33. Select State 3 and add a ‘Play Animation’ action. Beside ‘Anim Name’ choose ‘DoorClosed’
34. Test the game and when you go to the door it will open. When you leave it will close.
can it use 2021
Excellent, thanks a lot !!!
Thanks for the tutorial! But when I add property and move the slider to 1 sec, then slide the door open, no key frames appear to be added, any suggestions? I've followed your steps up until you say "now you should see the key frames being added".
Make sure the record button is on (small red circle in top left corner) or alternatively you can add a keyframe manually by selecting the property you want to animate, e.g. Position (in the left panel of the Animation window) and choose 'Add Key' by clicking on the keyframe icon for that property. Hope that helps!
I was wondering, If I need to create another door, what should I do? I've copied the door but the animation played at the first door's location.
You need to add a prefab, but change the collider. Basically, if you have a collider at door 1 and you have a prefab for the same door and its door 2, since its the same collider in the prefab it will activate both doors, change the name for each door and the door’s fsm. Sorry I responded 4 years later lmao
@@CadaverKuma Damn, better late than never huh haha
trigger not working!