Gameplay Cutscene Events
An in-game cutscene event, for this article, refers to events in which an animation plays in response to a trigger. For example, when the Player pulls a lever and a door opens, sometimes the camera view changes to highlight the event, other times it challenges the Player’s attention in different ways.
Objective: An overview of how I created a script that detects when the Player collides with a trigger, then plays an animation as a response using Timeline.
Table of Contents
· Setting up a Trigger Object
· Trigger Script
· Timeline Animation
· The Result
Setting up a Trigger Object
Let’s start by setting up a trigger, we want a cube with the following components:
- Box Collider: Make sure to check the Is Trigger box.
- Rigidbody: Make sure that Use Gravity is not tweaked, and is kinematic checked.
Make sure to size your cube adequately so the Player can easily collide with it, and then turn off the mesh renderer.
Trigger Script
Make sure to tag your Player with a specific unique tag such as well… “Player”.
The Player should have a Rigidbody just like the cube.
Our script is pretty simple, we just need to detect collisions that specifically come from objects with the “Player” tag. This script is attached to the trigger.
Code Highlights:
We start by searching for a collider, the “other” which refers to any object with a Rigidbody that can interact with our Trigger.
Then we search for the specific tag to ensure that only the object with the Player tag is registered.
We activate the director so that the Timeline animation plays automatically as soon as the Player is detected in the trigger.
Note: You can familiarise yourself with collision logic here.
Timeline Animation
The script needs a global variable to add the Director to the Inspector. That way, we can easily access it via code.
Note: If need to know how to create a Director with a Timeline, click here.
With the Director in the Serialized slot, we can activate it via code, as such, the Director object will be deactivated in the scene until the script changes its state.
The Playable Director is set to Play On Awake, when it becomes active by our trigger it will start to play the contents in the Timeline.
Timeline highlights:
An activation track handles how long the particle effects remain active on scene before they disappear.
A spaceship has been animated using Timeline to make it seem like it slowly spawns out of a portal. This spaceship is handled by both an animation track and an activation track so that it disappears after completing its flight path.
The Particle System has been animated by changing its scale from small to big to make it seem like it spawned there. This animation was made with the animation window, and it just plays as soon as the Activation Track activates the particle system(animation is set to play on awake).
Note: If you need help getting started with Timeline animations, check this out.
The Result
For this project, the camera control/view isn’t taken away from the player instead, a sound effect plays as the portal spawns to grab the Player’s attention. The sound has spatial awareness, which directs the Player to its location.
I’m currently looking for opportunities in the video game industry, check out my portfolio!