Color Collide Demo

v1.0

In this simple demo game, the player moves a horizontal square around a room with colorful spikes. The goal is to have a spike which matches the color in the backround hit the square, without letting another color hit it. Points go up, points go down. Get a lot of points!

This scene will demonstrate use of the ActionOnTrigger component, Conditionals, and utilizing the Blackboard to store data and react based on changes to that data.

Spikes

Each Row in the scene has a number of Blue, Yellow, Green, and Red spikes.

These each have an ActionOnTrigger component. This way, when the spike and the player cube come together, actions are executed.

However, there is a Conditional attached to the Trigger Collision group in the On Enter Actions ActionExecutor. The conditional looks for a global Action Blackboard object with the key "Hit Color Object". If the value and message do NOT equal the "Blue" object and string, then we pass the conditional, and the actions will execute.

This conditional keeps the actions from executing when the target color for the player matches the color of this spike.

At runtime, we can select the Action Blackboard object in the scene, and view the data held on the blackboard.

While the "Hit Color Object" is Blue, the spike will not trigger. It will ignore collisions with the player object. Red, Yellow, or Green objects which look for their own color will trigger the actions.

There are four actions. The first is a Debug.Log, intended to help with the demo. Then, we use PauseTimeAction to pause the timeScale for 0.2 seconds, and SendBlackboardEvent with the key "Shake".

Finally, we use SendBlackboardNotificationAction to add a notification to the Blackboard with the key "Hit Color Object", the object we hit, and the "Blue" string in the "Message" portion of the notification.

"Events" are received by the Action Blackboard, but are not stored. The data is not saved on the Blackboard itself, but subscribers to the Blackboard can receive events and handle them, if they'd like.

"Notifications" are stored on the Blackboard, so objects can always look up the latest data by the key.

Player Cube

The Player Cube is the small square that represents our player. The PuzzleDemoCharacter class has two ActionExecutors, one for "No Score Hit" and one for "Score Hit". Each play an audio clip, and increment the "Score" value on the Action Blackboard β€” though each has different values for these.

The PuzzleDemoCharacter class inherits from JuicyActionsBlackboardFollower. This means it will automatically subscribe to the Action Blackboard, and can override methods like OnBlackboardNotification().

In that override method, we check to see if the BlackboardNotification object matches the key we are looking for. If not, we return and ignore the notification.

We check to mke sure the value of the notification is a GameObject, and we cache the value in the field go.

We then make sure the GameObject has a Renderer, and cache that value in the field objectRenderer. If the material color is the same as our targetRenderer.material.color, then we return out. The color of the targetRenderer is set to be the same as the last spike hit, so we're basically saying "If this is not a different color, then return."

If we got this far, then we set the color to match the color in the notification, and then we compare the name of the color to our currentActiveColor value β€” at the end we will cache the new "Active Color" as the currentActiveColor.

This is how we determine if we execute the scoreHit actions or the noScoreHit actions.

Back Walls

The walls of the play area indicate the target color for the player. The Environment object has a ColorCollideEnvironment component on it, which inherits from JuicyActionsBlackboardFollower.

This holds an array of Renderers, and we override OnBlackboardNotification. If the notification matches what we are looking for, we update the renderers to the new color.

We hope this demo helped to illustrate how the Action Blackboard can be used to share data and events between objects efficiently.

Demo Scenes

Last updated