5. Bad Guy Interactions
v1.0
Now lets set up the bad guy. In this demo, the player will be able to "Stomp" on the bad guy, and the bad guy will attack the player if the player gets too close.
Player Getting "Hit"
Make sure there is an "Enemy" layer, and put the "Spitter" into that layer. Add a Box Collider and set isTrigger true, as well as a Rigidbody component.
Next, add a BoxCollider to the PlayerArmature, and set the values similar to the head collider from step 4. This will be our foot trigger for stomping.
Add another Action On Trigger component, and set the Trigger Collider value to be the new Box Collider by dragging the Box Collider into the field.

At the bottom of Action On Trigger, set the "Enemy" as the only layer in the LayerMask.
Add the Trigger Unity Event action to the On Enenter Actions list. Have it call the HitEnemy() method on Player component.

Check out the Player.cs script. The HitEnemy() method will collect the Collider from the enemy that was hit. It then determines if the players Collider was higher than the enemies. If so, then the enemy has their GotHit() method called — and that method calls their GotHitActions Action Executor.
However, if the players collider is not above, then the Action Executor on the player, GotHitActions, will be executed.
This trigger will be used for both the player jumping on the enemies, and the enemies attacking the player. In your game, you likely will have your own logic for player/enemy interaction.
Player Got Hit
Open PlayerArmature and the Player component, the "Got Hit Actions". Add a Move action, and override the Move Settings so that the player is pushed back from their forward direction.

Next, we can turn off the Animator and ThirdPersonController. There is no "gotHit" animation for this character, so we'll simply turn off the Animator to stop motion, and add more juice to make things exciting when the player gets hit.
There are methods on Player.cs that handle turning on and off components. They should be populated with the Animator and ThirdPersonController.
Add a Send Unity Event action, and set it to call DisableComponents() on the Player. Duplicate it, and choose EnableComponents().
Put the the disabling action above the Move action, and the enabling action below. This way we will turn them off first, and turn them back on after we are done with the move. Click the "Clock" icon in the Move action header and set the "Time Before Next Action" to be determined by the action. This way, the actions after Move will only happen after the movement has ended.

Add More Juice!
Now we can add even more actions. We'll put these actions before the Move action in the list, so that their start is not blocked by the Move action.
Player Color
Add a Color Change action so we can make the mesh flash red.

Camera Shake
Copy the Send Blackboard Event action from the Box object. Paste that into our list to make the camera shake.
Screen Vignette
Add a Set Vignette Intensity and Set Vignette Color action to the list. Populate the required fields, and set the target intensity to 0.4 and the color to red. Also ensure the "Revert to Base" is selected, and choose an Animation Curve that works for you, perhaps one that fades the effect in then out.


Got Hit Audio Clip
Add the Play Audio Clip action, and assign a suitable audio clip. Perhaps "Bullet Hit" from the SciFi Shooter Demo.
Got Hit Cooldown
Often you'll want to ensure the player can't get hit over and over in quick succession. There's many ways to account for that. For this demo, being simple, let's handle it via the Juicy Actions system!
Toggle off the "Restart" button in the header of the Got Hit Actions, so it says "Can't Restart".

This means that the sequence must finish before it will start again. Currently it finishes in 0.1 seconds, because only one of the actions has a timer on it — the Move action.
Duplicate the Color Change action, and put it at the bottom of the list. Change the color to green or something you prefer, and add an Animation Curve that wiggles up and down.
Set the time to be 0.4, and then set the actions Time Before Next Action to be determined by the action. This means that the value of 0.4 will be used — or any other value that you find more appropriate.

Now, when the player is attacked or hits the bad guys, they'll have a 0.5 second cool down before being able to be hit again, and a visual green "flash" to indicate they're in the cooldown state. If you prefer to have a cooldown without any visual cue, try using the Wait action at the end. This action just forces the executor to delay by an amount you set.

Stomping on the Bad Guy
Now we have the logic set up for actually stomping on the bad guy, lets add the Juicy Actions to make it feel great! (and to destroy them)
We'll be focusing on the Got Hit Actions Action Executor on the Spitter component. The class already has a TurnOffOnStomp() method that will turn off the Box Collider when the enemy is stomped. Start with a Trigger Unity Event action and select the Spitter object and class, and the TurnOffOnStop() method.

Add a number of other actions to add some sweet juice to the event.
Camera Shake
Copy the Send Blackboard Event from the box we set up earlier, and paste it into this list, so we shake the camera.
Color Change
Add a Color Change action, and turn the color red. We do not need to do this over time, or revert.

Set Vignette Intensity & Color
Add a Set Vignette Intensity action and Set Vignette Color action. Set both to revert to base, and have a duration of 0.1 seconds. Choose a color that isn't red and isn't white -- perhaps cyan. The animation curve should be set to a flat value of 1. This means that the effect will happen immediately, but since we have a 0.1 second duration, it will revert very soon after.
This is the same as doing two actions 0.1 second apart, with no Animation Duration.


Play Audio
Add a Play Audio Clip action and choose your favorite "death" clip.

Freeze Time
Next, add a Set Timescale action. For this, let the action determine the Time Before Next Action, and set the Effect Duration to 0.2. Set Return to Base Timescale to be true. This will pause the time for 0.2 seconds, including all motion that is utilizing the Juicy Actions timescale.

Squash the Enemy
Next, below the Set Timescale action, add a Scale action. Set the target scale to 1, 0, 1, essentially flattening the bad guy. Set the duration to be 0.2, and the curve as you'd like.

Count the Kill
Copy the Increment Blackboard Value from the Box object, and paste it into the enemy. Update the key to "Enemies Stomped".

To have the value displayed in the UI, copy the TMPBlackboardDisplay component from the Boxes Smashed object under the Canvas. Change the string values as required, with the key "Enemies Stomped" to match the key used in the Action. Don't forget to update the Text reference.
Enemy Go Boom
If you haven't yet, install the "Particle Pack" from Unity Technologies in the Asset Store. We'll be using it!
Add a Spawn Object action, and populate the prefab with the TinyExplosion - Demo object.
All done!
That's it! Feel free to add any additional actions you'd like, tweak settings, add music, and so on. I hope this tutorial helped illustrate many of the use cases for Juicy Actions, and that you can clearly see the benefits for utilizing this system as part of your workflow.
Last updated