How to use Actions/Skill and Animation Events
Last updated
Last updated
You can play animations without code with the Simple Play Motion component in just two steps:
1- Create a Animation State on a Custom Action Layer and assign an animation:
It is recommended to create a copy of the default animator controller to edit it, so if you make a mistake in some edition you can easily return to the original file.
2- Add Simple Play Motion component to your JU Character and configure it:
Simple Play Motion Properties | Description |
---|---|
Action Duration | Motion duration |
Enter Transition Speed | Enter animation state speed |
Exit Transition Speed | Exit animation state speed |
Target Layer | Body part to play animation, if you look at the Custom Action Layers of the default Animator Controller, each layer controls a different body part |
Animator State Name | Animation state name |
Start Motion At | You can cut the beginning of the animation with this option |
Input To Call Action | Input to start action |
Force Fire Mode | While the action is playing, set FireMode to true |
Force No Fire Mode | While the action is playing, set FireMode to false |
Block Character Locomotion | While the action is playing, the character does not move |
Start Action Even State Is Playing | With this option it is possible to start the action even if it is already playing |
Result:
JU TPS has classes and scripts to create actions, emotes or abilities.
The JUTPSAction
class is made to interact with the JU Characters system, it has references of JU Character Controller, Animator, Rigidbody, Collider and Camera.
JUTPSAnimatedAction
is made for actions involving animations, and has functions to interact with the default JU TPS Animator Controller.
To use these classes you need to make your skill script inherit the classes:
See sample code below:
This code plays in an animation (line 16 to 21) and makes the character fly and look in front of the camera (line 26 to 31), it also unequips items when the action starts and equips the last used item when the action ends (line 35 to 47). See the result:
The code also has a function to spawn a magic attack at character hand position, but it won't do anything by itself, to make the magic spell attack work, let's go to the next topic.
It is possible to invoke functions through Animator easily without having to create animation events directly in animations.
1- Add the JU Animation Event to your animation state and give your event a name, and configure at what time the component will call your event(Duration propertie)
2- Add the JU Animation Event Receiver, create an event with the same name you put in the JU Animation Event, and in the Event call the function you want:
See the result: