You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a animation controller and add it to the component.
Setup the Blend Tree
On the base layer of the animation controller, add a blend tree. Change it's type to 2D Freeform Directional.
Create parameters "VelocityX" and "VelocityZ" of type float in the animator. Add these as the blend tree's parameters as well.
Add the animation clips for walking, running and idle found in Assets/Animations/Clips to the Blend Tree. Change the Velocity X and Z of every clip to match the direction and speed, so for example idle would be (0, 0), walk forward would be (0, 1) and run forward would be (0, 2).
In the player script, setup the script to update the animator's parameters previously mentioned.
Get the animator component of the player object. Get the hashes of the velocity variables as well.
In the update method, set the animator's parameters to match the movement speed using animator.SetFloat(hash, value) for both the x and z velocity.
Animation Layers and Masks
In the animation controller, add a new layer for the torch.
Set its weight to 0.1.
Create an avatar mask for the YBot and add it to the layer.
In the inspector, while the mask is selected, import the Y BotAvatar as a skeleton and deselect all nodes except for maxamorig:LeftShoulder and its children.
In the Animator window, setup the states.
Create an empty clip by right clicking for the default state.
Add the animations in Assets/Animations/Clip/Torch to this layer. Add the Equip Torch clip twice, name the second one "Unequip Torch" and change its speed to -1.
Add a new bool parameter to the animator named IsTorchEquipped.
Add transitions between the states so they go like Empty -> Equip -> Idle -> Unequip -> Empty.
For the transition from Empty to Equip, turn off Has Exit Time and add a condition for IsTorchEquipped == true.
For the transition from Idle to Unequip, turn off Has Exit Time and add a condition for IsTorchEquipped == false.
In the player script, setup the script so it updates the IsTorchEquipped variable is toggled to true or false in the OnAttack method.
Add a bool isTorchEquipped to save whether the torch is equipped with a default value of false. Add a variable to save the hash of the IsTorchEquipped variable as well.
In the OnAttack method, switch the script's isTorchEquipped to the opposite value and update the animator's parameter to match using animator.SetBool(hash, value).
Toggle torch visibility using events
Open the Y Bot in the "Animation" window. In there, select the "Equip Torch" clip, and find the moment in time you want the torch to appear at. Right click to add an animation event at that point in time.
In the player script, add a public method to toggle the activeness of the torch using the SetActive and activeSelf methods on the torch.