Supporting our Community:
We’re making Learn Premium available to all users in perpetuity.
Start Learning.

Week 5: Gameplay Mechanics | Apr 20 - 24

5 Hours
Your progress
Also included in
This week, you will program an arcade-style Sumo battle with the objective of knocking increasingly difficult waves of enemies off of a floating island, using power ups to help defeat them. In creating this prototype, you will learn how to implement new gameplay mechanics into your projects, which are new rules or systems that make the game more interesting to play. On one hand, you will learn to program a powerup, which give the player a temporary advantage. On the other hand, you will learn to program increasingly difficult enemy waves, which make survival more challenging for the player. A good balance of powerups and increasing difficulty make for a much more interesting gameplay experience.
Select your Unity version
Last updated: April 23, 2020
Week 5: Gameplay Mechanics | Apr 20 - 24
Prototype4 Upgrades
Lots of upgrades, including: JumpBlast, Speed Boost, and Projectiles (which destroy enemies)! The player has multiple lives, with automatic respawn after falling off the edge. There are three enemy types, differing in health, size and speed. Not featured: number of enemies killed and Game Over message which appears in Console window upon final death. The most interesting challenge was programming JumpBlast. After trying several different approaches (including animation, which didn't play nice with Physics), I found that calling a coroutine was the best solution: IEnumerator JumpBlastForceRoutine() { // Allow the player time to jump into the air playerRigid.AddForce(Vector3.up * powerupForce, ForceMode.Impulse); yield return new WaitForSeconds(0.4f); // Make the player slam quickly back to the ground playerRigid.AddForce(Vector3.down * powerupForce * 3, ForceMode.Impulse); } In OnCollisionEnter, I added the following code to play the blast particles and push away any enemies that might be too close to the player: int enemyLayerMask = 1 << LayerMask.NameToLayer("Enemy"); if(collision.gameObject.CompareTag("Ground")) { isOnGround = true; if (hasPowerup) { blastParticles.Play(); // Push away all nearby enemies with JumpBlast Collider[] nearbyEnemies = Physics.OverlapSphere(transform.position, blastRadius, enemyLayerMask); foreach (Collider enemyCollider in nearbyEnemies) { Debug.Log(enemyCollider.gameObject + " is within blast radius"); Rigidbody enemyRigid = enemyCollider.gameObject.GetComponent<Rigidbody>(); Vector3 awayFromPlayer = enemyCollider.gameObject.transform.position - transform.position; enemyRigid.AddForce(awayFromPlayer * powerupForce, ForceMode.Impulse); } } } This was a pretty fun challenge to complete. Thanks for the great instructions! ~AH