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