"Prisoner" balls

Not hugely extreme tuning, but kind of fun. For every destroyed block another player ball is released. It spawns in the place of the broken block and goes off to cause it’s own mayhem. It’s different colour from the main player ball and it ignores the collision with the ground plane, so it doesn’t trigger the end of game when the escaped “prisoner” ball falls through. So on one hand it’s helpful, on the other provides a bit of visual distraction to the player, as you still need to make sure you keep the main ball from falling through.

2 Likes

Hello there !

Seems like your tuning is very good and i’m amazed how you have made a ball for every block destroyed. I just want to know what you have changed in the code, and if you could share your knowledge with us :smile:
All the best wishes and good luck my friend :grin:.

1 Like

Hey Pravachan,

Thanks a lot for your kind words! I’m not sure how much knowledge I have to share haha, but happy to share my code and workflow of course. I just tried to use what Rick taught us in previous lectures.

Here’s my workflow for creating the extra balls. I duplicate the Ball prefab. Rename it to BallPrisoner and add a custom tag “PrisonBall” for the prefab.

Then in the code for Block.cs, I add

[SerializeField] GameObject prisonerBall;

This allows me to connect my BallPrisoner prefab into it.

Then inside Rick’s sparks trigger method - triggerSparklesVFX() I add the line that creates an instance of the BallPrisoner every time a block is destroyed.

GameObject prisoner = Instantiate(prisonerBall, transform.position, transform.rotation);

That’s it for creating a ball for every block destroyed :slight_smile:

Then for making them move and ignore collisions with the ground triggering the “game over” state, I head into Ball.cs script and add this bit of code to the Start() method:

    if (tag == "PrisonBall")
    {
        hasStarted = true;
        myRigidBody2D.velocity = new Vector2(xVel, yVel);

        CircleCollider2D colliderBall = gameObject.GetComponent<CircleCollider2D>();
        BoxCollider2D colliderFloor = FindObjectOfType<LoseCollider>().GetComponent<BoxCollider2D>();

        Physics2D.IgnoreCollision(colliderBall, colliderFloor);
    }

Hope that’s useful :slight_smile: Good luck on your developer journey as well! :love_you_gesture: :love_you_gesture:

1 Like

Awesome!

I really like the idea of a double-edged-sword kind of power-up. Like one or two balls get released and the player thinks, “Oh sweet!”. But then like five are flying everywhere and suddenly it’s, “OMG! Abort, ABORT!” :rofl:

1 Like

Haha yes, thank you :slight_smile: I originally thought to leave them colliding with the ground making the player loose, but then I thought that was just too hardcore. It’s bad enough trying to see which ball is the Player ball, when all this mess is happening :smiley:

Great ! !
Thank you for sharing. What you have done is very cool stuff that i was curious to try too and making me ask you for the code :sweat_smile:. This was wonderful :ok_hand: :ok_hand:.

I really wish to develop to a developer too :sweat_smile: :laughing:.
Man, thank you for sharing :grin:.

Good Luck ....:)
1 Like

Happy if it was useful :slight_smile: :love_you_gesture: :love_you_gesture:

Privacy & Terms