3. Juicy Player Speed

v1.0

If you haven't yet installed Post Processing, do so now. We'll be utilizing that in various ways to add great visual effects. Don't forget to add a Post Processing layer for the Post Processing Layer component on the MainCamera in the scene.

The player can walk and run. We can juice this up by adding some effects to the camera and Post Processing.

Set Player Speed to Blackboard

We've exposed the ForwardSpeed of the player in Player.cs. Lets add a new method, called from Update() which we will name SetForwardSpeedToBlackboard().

private void SetForwardSpeedToBlackboard()
{
    if (ActionBlackboard.Instance == null)
    {
        Debug.LogWarning("[Player] ActionBlackboard.Instance is NULL - cannot set Forward Speed");
            return;
    }
            
    var speed = ForwardSpeed;
    ActionBlackboard.Instance.SetValue("Forward Speed", speed);
}

Now, when we press play, open the Action Blackboard object in the Inspector. We will see the Forward Speed value.

Now that this value is on the ActionBlackboard, all Actions and Action Executors will have access to it, for use in Conditionals or custom Actions that utilize the value.

Action Runner to Set Values

Add an Action Runner component to the PlayerArmature object. We will make three groups of actions, dependent on the speed the player is moving.

Make a new Group

We may want different settings for different speeds. Create a group by pressing the "Grup" button with the folder icon, and choose Create New Group. This moves the Action into a group, which we can call "Fast Movement".

Set Conditionals

We only want this Action to execute when the Forward Motion of the player is above a certain threshold. Click the "Conditionals" tab in the expanded Fast Movement group. Then click "Add Conditional".

In the dropdown, select "Blackboard Value". By default this is using the ActionExecutor, so click the "Global" toggle so that we utilize the global ActionBlackboard.

Set the Key to "Forward Speed". This is the key we're passing in from the Player class.

Toggle on "Value", choose the type "Float", and set "GreaterThanOrEqualTo" and a value of 7.

Now, the actions in this group will only trigger when the value of "Forward Speed" reaches at least 7.

Set Camera Field of View

Then, add a SetVirtualCameraFieldOfView action. Populate the Virtual Camera field with PlayerFollowCamera (CinemachineCamera component).

The Vertical FOV on the CinemachineCamera component is set to 40. We'll increase this when motion hits a certain value, to give the sense of faster motion.

Set the Target Field of View to 50, and the Animation Duration 0.2 for a faster transition.

Chromatic Aberration

In Fast Movement group, add a Set Chromatic Aberration action. Move it above the Stop Action Sequence.

Populate the Volume with Post Processing Volume from the Hierarchy. Set the Animation Duration to match the Field of View change, and set the Target Intensity to 0.3.

Bloom Threshold

Do the same steps as above but with the Set Bloom Threshold Action. The value is set to 0.9, so reduce it to perhaps 0.6 for Fast Movement.

Pausing Execution While True

Once we have our speed set, we don't need to change the values, so we can hold the Action Executor until we need to change values. We can do this with a Conditional Step Action. Add one now.

This action will hold the execution of actions until the conditions are met. Add a condition and click the "Edit" button. Select the Blackboard Values option and populate the Forward Speed, and the value to check for a float that is "less than" 7.

When the "Fast Movement" group enters, we'll set the values on various components to change the effects. So long as the Forward Speed value remains above 7, the Action Executor will be essentially paused.

When the value drops below 7, we'll let the execution continue.

Ending Actions Early

Add a Stop Action Sequence action at the end. This action will stop the Action Executor early β€” it will start again after because the Action Runner class is set to auto restart, but this time, different conditions exist, so a different movement group, which we'll create next, will be activated.

Create other Speeds

Duplicate Fast Movement using the "Duplicate" button (two rectangles).

Name the new group "Slow Movement", and set the Field of View value to 44, and the Conditional value to 3.5.

Set the Bloom to 0.8 and the Chromatic Aberration to 0.

In the Slow Movement Conditional Step Action, add a second conditional, and set the values to be "Greater than or equal to 7" or "less than 3.5". This way, as long as the Forward Speed is between 3.5 and 7, we'll remain at this state. (Don't forget this is an "or" operator).

Duplicate either of the group, name it "No Movement", and set the Field of View to 40, and the Conditional Value to be "Less than" 3.5.

Set the Bloom to 0.9 and the Chromatic Aberration to 0.

The Condition Step Action can have just one check, for "Greater than or equal to 3.5."

Press play β€” now when we move forward we can see new visual effects based on the speed.

Last updated