Unity 2D CHECKPOINTS Tutorial (Simple and Easy!) | Unity 2D Platformer Tutorial #9
Summary
TLDRIn this engaging video, the creator guides viewers through the process of implementing a checkpoint system in a game. Starting with scene modifications, including a new background color, moving platforms, and duplicated obstacles, the tutorial then demonstrates how to respawn players from the beginning upon collision with obstacles. The main focus is on adding checkpoints with custom images, using box colliders with the 'Is Trigger' feature, and scripting to update the player's respawn position. The tutorial also covers spawning the player slightly above the checkpoint, changing checkpoint images upon activation, and disabling checkpoints after interaction to prevent multiple respawns. Finally, the creator shows how to create a prefab for easy reuse of the checkpoint system, concluding with a call to action for viewers to subscribe for more content.
Takeaways
- 🎮 The video is part of a game making series focusing on implementing a Checkpoint System.
- 🛠️ The scene for the video has been updated with a new background color, moving platforms, and duplicated obstacle objects.
- 🔄 The player respawns from the starting point when hitting an obstacle, as previously implemented in the respawn system.
- 📍 Two images have been created for the checkpoint and added to the project.
- 📐 A box collider with the 'Is Trigger' feature is added to the checkpoint object for interaction.
- 📝 A checkpoint script is created to manage the game's checkpoint logic.
- 🔄 The 'startPos' variable in the GameController script is renamed to 'checkpointPos' to store the last checkpoint position.
- 🔄 An 'UpdateCheckpoint' method is introduced to update the 'checkpointPos' when the player reaches a checkpoint.
- 🔝 An empty 'respawn point' object is created to determine the exact spawn location above the checkpoint.
- 🖼️ The checkpoint image changes upon activation to provide visual feedback.
- 🔄 Additional checkpoints can be added by duplicating existing ones, allowing the player to respawn from the last checkpoint reached.
- ❌ The checkpoint's collider is disabled after interaction to prevent multiple interactions with the same checkpoint.
- 🛠️ The checkpoint object is turned into a prefab for easy reuse in the game development process.
Q & A
What is the main focus of the video?
-The main focus of the video is to create a Checkpoint System for a game.
What changes were made to the scene for this tutorial?
-The changes made to the scene include changing the background color, adding a moving platform, and duplicating the obstacle object.
What happens to the player when they hit an obstacle in the current system?
-In the current system, when the player hits an obstacle, they respawn from the starting point.
What is the purpose of adding a checkpoint to the game?
-The purpose of adding a checkpoint is to allow the player to respawn at a specific point in the game after they die, rather than starting over from the beginning.
How many checkpoint images were created and added to the project?
-Two checkpoint images were created and added to the project.
What is the role of the box collider added to the checkpoint object?
-The box collider is added to the checkpoint object to detect when the player reaches the checkpoint, with the 'isTrigger' feature enabled to handle the interaction without physical collision.
What variable is renamed in the GameController script and what is its purpose?
-The variable 'startPos' is renamed to 'checkpointPos' to store the position of the checkpoint, which the player will respawn at if they die before reaching any checkpoint.
What is the purpose of the 'UpdateCheckpoint' method in the GameController script?
-The 'UpdateCheckpoint' method is used to update the position of the 'checkpointPos' variable when the player reaches a new checkpoint.
Why is an empty object named 'respawn point' created in the checkpoint?
-An empty object named 'respawn point' is created to determine the exact height where the player should spawn above the checkpoint.
How does the checkpoint image change when activated?
-The checkpoint image changes when activated by dragging and dropping the new images into their respective slots in the checkpoint script.
What is the solution if a player touches a previous checkpoint and wants to respawn from the last checkpoint instead?
-The solution is to disable the collider of the checkpoint once it makes contact with the player, preventing it from interacting with the player a second time.
What is the advantage of creating a prefab from the checkpoint object?
-Creating a prefab from the checkpoint object allows for easy reuse and placement of the checkpoint in the game wherever and whenever needed.
Outlines
🛠️ Implementing a Checkpoint System in Game Development
This paragraph outlines the process of creating a checkpoint system in a game development series. The video begins with an introduction to the task and the changes made to the game scene, such as altering the background color, adding a moving platform, and duplicating obstacle objects. The current respawn system is discussed, which respawns the player from the starting point upon death. The tutorial then proceeds to add checkpoints to the game, introducing two checkpoint images and detailing the steps to add a box collider with the 'isTrigger' feature to the checkpoint object. A checkpoint script is created to update the player's respawn position upon reaching a checkpoint. The script involves renaming the 'startPos' variable to 'checkpointPos' and creating a method 'UpdateCheckpoint' to change the respawn position when a checkpoint is reached. The player's interaction with the checkpoint is tested in the game, demonstrating that the player respawns at the checkpoint after passing it. Additional features like adjusting the spawn height and changing the checkpoint image upon activation are also covered. The paragraph concludes with the creation of a prefab from the checkpoint object for easy reuse.
📦 Creating a Prefab for Reusable Checkpoints
In this paragraph, the focus is on streamlining the game development process by creating a prefab from the checkpoint object. The speaker explains the benefits of using a prefab, which allows for easy and efficient use of the checkpoint system in different parts of the game or in future projects. The process involves duplicating the checkpoint and testing the game to ensure that the player respawns correctly from the last checkpoint reached. The tutorial also addresses how to prevent the player from respawning at an earlier checkpoint after reaching a later one by disabling the collider of the checkpoint once it has been activated. The paragraph wraps up with a demonstration of the checkpoint system in action, showing the player respawning at the first and second checkpoints and then from the last checkpoint after touching an earlier one again. The creation of a prefab simplifies the process of implementing checkpoints, making it a valuable tool for game developers.
Mindmap
Keywords
💡Checkpoint System
💡Respawn
💡Collider
💡Game Controller Script
💡UpdateCheckpoint Method
💡IsTrigger Feature
💡Respawn Point
💡Transform Variable
💡Image Change on Activation
💡Duplicating Checkpoints
💡Prefab
Highlights
Introduction to the game making series and the goal of implementing a Checkpoint System.
Scene modifications including a new background color, moving platform, and duplicated obstacle objects.
Demonstration of the player respawning from the starting point upon hitting an obstacle.
Introduction of the checkpoint concept to improve the respawn system.
Use of two images for the checkpoint and their integration into the project.
Adding a box collider to the checkpoint object with an enabled 'isTrigger' feature.
Creation of a checkpoint script to manage game state.
Modification of the GameController script to handle checkpoint positions.
Implementation of the UpdateCheckpoint method to change the respawn position.
Linking the checkpoint script to the GameController for dynamic respawn points.
Adjusting the player's spawn point to be above the checkpoint image.
Adding an empty object named 'respawn point' to control the exact spawn location.
Changing the checkpoint image upon activation for visual feedback.
Duplicating checkpoints for extended game levels.
Ensuring the player respawns at the last reached checkpoint.
Disabling the checkpoint collider after interaction to prevent multiple interactions.
Creating a prefab from the checkpoint for easy reuse in the game.
Encouragement to subscribe for more video content and a closing statement.
Transcripts
Hello everyone,
Let's continue the game making series.
In this video we will make Checkpoint System.
All right! Let’s get started.
I made a few changes to the scene for this video.
I changed the background color,
added moving platform
and duplicated the obstacle object,
just that's it.
Let’s start the game in this case.
As you can see,
the player respawns from the starting point
when hit the obstacle.
we did the respawn system in the previous video.
No matter how far the player goes,
when it die, it is respawned from the beginning.
Let’s add checkpoint to the scene.
I made 2 images for checkpoint
and added them to this project.
I’ll drag and drop the checkpoint image onto the scene.
And I’m gonna add box collider to the checkpoint object.
set the size of the collider .
and then I’ll enable istrigger feature of the collider.
I’m gonna create checkpoint script.
Open the checkpoint script.
First of all, I will make a small addition to the game controller script .
As you can see, when the player dies, they only respawn from the starting point.
I will rename the startPos variable to checkpointPos.
checkpointPos will be equal to the player's starting position
when the game first starts.
If the player dies before reaching any checkpoint,
it will respawn from the starting point.
I will create a new method called UpdateCheckpoint.
when the player reaches any checkpoint,
I will call this method from checkpoint
script and i'll change the position of the checkpointPos variable.
Alright!
Save this script and go back to checkpoint script.
I’ll create a variable named gameController
to access the GameController script.
if the player touches the checkpoint,
I will update the position of the checkpointPos variable
to the position of the touched checkpoint.
ok! save the script and go back to unity.
Start the game.
if we die before reaching the checkpoint,
we spawn from the starting point.
When we die after reaching the checkpoint,
we are respawn at the checkpoint.
I want the player to spawn slightly above the checkpoint image.
Click on the checkpoint object and create an empty object named respawn point.
i raise this empty object to the height i want the player to spawn.
Open the checkpoint script. I’ll create a Transform variable
named respawnPoint.
Go back to unity.
Drag and drop respawnPoint object to this slot.
Start the game.
As you can see, the player now spawns above the checkpoint.
I want its image to change when the checkpoint is activated.
If you want, you can add animation or do different things,
it's completely up to your taste.
drag and drop the images into the their slots.
Nice !
As soon as the checkpoint is activated, its image changed.
i want to add one more checkpoint to the scene,
so i will duplicate this checkpoint with CTRL+D shortcut.
Start the game.
as you can see the player respawns from the last checkpoint.
if the player touches the previous checkpoint again,
it spawns from the previous checkpoint.
If you don't want this to happen, we can simply solve it.
Go back to checkpoint script.
I'll access the collider of the checkpoint.
As soon as the checkpoint makes contact with the player,
I will disable its collider.
so it will not be able to interact with the player a second time.
Save the script and Let’s test it.
I reach the first checkpoint, died and respawn from the first checkpoint.
I reach the second checkpoint, died and respawn from the second checkpoint.
I touched the first checkpoint again,
died and respawn from the last checkpoint.
Nice!
I'll create a prefab from the checkpoint object.
so I can easily use the checkpoint whenever and wherever I want.
I hope the video useful for you.
Please don’t forget to Subscribe for more videos.
Thanks for watching.
See you in the next video.
Ver Más Videos Relacionados
How To Make A Game with GDevelop - Levels (E09)
Create a Nature Environment using Geometry Nodes | Blender Beginner Tutorial
Collision Detection - How to Make a 2D Game in Java #6
QR Code Makeup on ComfyUI using ControlNet Brightness Method. (MacBook Pro Intel i7/i9 )
How to make a Roblox JOJO game #2 | Making Stand Combat
DX100 - Collision Detect (Code 4315)
5.0 / 5 (0 votes)