2D Unity Lab 4
2D Unity Lab 4
Re-spawning|Particle Effect
__________________________________________
4
Basic Rigidbody2D properties
• Mass: the weight of an object/character
• Gravity: you can make it behave exactly like in the real world, or you could
make a world with little to no gravity. Gravity affects how things move, how
high character can jump, and how an object reacts to a force against it
• Fixed Angle: can the object spin when hit by something else?
• Radius: how big or small the circle collider is around the game object
• Size: how big or small the box collider is around the game object
• Offset: how far away the collider is from the game object itself
• Is Trigger: If checked, a GameObject can trigger an event when it collides with another
GameObject. This is useful for setting up events you want to happen when your player comes
in contact with them.
• Example: when the player runs into an enemy, it dies
Hinge Joint Constraint
• The most common use of a hinge joint in Unity is to create a trapdoor for your
player character to fall through
• Unlike your player character, you don’t want your platform or ground to fall away
due to gravity!
• So we add a hinge constraint to tell the physics engine that the object has a point
on it that will constrain it to its position on the screen but allow it to rotate with
the force of gravity without actually falling. There are a few different constraint
types you are able to add to a Rigidbody2D Component.
• Slider Joint 2D: Constrains a GameObject along a set path, like an elevator
door. Can also be set to activate upon collision or continually
• Create three script files for each of our 3 newly-created game objects
• Spikes
• Checkpoints
• LevelManager
Exercise #16 - Checkpoints – Step 6: Write
LevelManager script Logic
• LevelManager script is responsible for tracking the current checkpoint, it will use
the current checkpoint’s position to return our player to it when respawned.
Exercise #16 - Checkpoints – Step 6: Write
LevelManager script Logic
(other.tag == “Player”)
• Now play the scene. Let the player run through the checkpoint first,
then run at the spikes. The moment he collides with them, he’ll
immediately respawn back at the checkpoint
Exercise #15 - Checkpoints – Step 8: Add collider
to checkpoint (for multiple checkpoints)
• Add Circle Collider 2D to the checkpoint game object and check ‘Is
Trigger’ so that the player can interact with it
Exercise #16 - Checkpoints – Step 9: Add Spikes
and Checkpoints Prefabs (for multiple
checkpoints)
• Drag your Spikes and Checkpoints game objects to your Prefabs folder in Assets,
so that you can create multiple Spikes and Checkpoints with same characteristics
Exercise #16 - Checkpoints – Step 10: Write
Checkpoints script logic (for multiple checkpoints)
(other.tag == “Player”)
• Now when player interacts with any checkpoint, Checkpoint script will
update the currentCheckpoint of the LevelManager so that the player
will be returned to the currentCheckpoint (the last checkpoint the
player interacts with) when spawned
Exercise #17 – Particle Effect (Animation)
• Particle effect is a unique tool that can add interactivity and
responsiveness to your games. They add to the fine-tuning and detail
of a game’s look and animation
• As in Mario games, the player can break bricks by colliding with them
• The idea we’ll play with is to swipe one sprite with another to create
the illusion of animating a particle effect
Exercise #17 – Particle Effect – Step 1: Add
Brick game object
• Add a Brick game object and place it on a suitable Sorting Layer
• Go back to Unity and drag and drop your ExplodedBlock sprite to its
variable.
Exercise #17 – Particle Effect – Result
• Now when the player game object hits the brick game object from
below, it will result in the brick exploding, then disappearing
References
• Hinge Joint2D Tutorial. URL retrieved from:
https://www.youtube.com/watch?v=l6awvCT29yU
• Endless Runner Game in Unity. URL retrieved from:
https://www.youtube.com/watch?v=GrQalFLtQT4&list=PLiyfvmtjWC_
XmdYfXm2i1AQ3lKrEPgc9-
• Checkpoints & Respawning - Unity 2D Platformer Tutorial - Part 3.
URL retrieved from:
https://www.youtube.com/watch?v=ndYd4S7UkAU
• HOW TO MAKE 2D PARTICLE EFFECTS - UNITY TUTORIAL. URL
retrieved from: https://www.youtube.com/watch?v=_z68_OoC_0o