Control number of downed pins placed in a pyramid shape

Hello! I would like to ask for help on how to manage and control the number of pins placed vertically forming a pyramid and that have been hit knowing that by hitting one, you can hit others and fall to the ground. How can I know which ones I managed to knock down by throwing a ball?

Thank you

It sounds like you’re making a bowling game, is that right? Have you considered making the ball and pins physics objects with RigidBodies, and letting the physics engine do the work for you? Just off the top of my head, I’d do it like this:

  • After the player throws the ball, wait for the ball to hit the first pin. Have some backup timer and/or trigger colliders to detect if the ball has gone completely out of bounds or just doesn’t make it there somehow
  • Once the ball enters the pin area, start a timer (this is how real life bowling alleys work I believe) of a couple of seconds
  • After the timer is over, look at all the bowling pins. if their local “up” direction still matches closely with Vector3.up, you know they’re still standing. Otherwise, you can assume they’ve been knocked over. Count the number of pins that were knocked over.
  • Assuming this is a normal bowling game, you can clean up the knocked down pins (move them offscreen or whatever) and leave the still-standing pins for a second throw.
  • Repeat the same for the second throw, and calculate the score based on how the two throws went

You’ll want to fine tune the masses and physic materials of the ball, pins, and the lane to give it the most realistic feel.

Thank you! I tried to get the value of transform.up.y and control the value in degrees of its rotation … with that for now it works for me … :slight_smile:

if (transform.up.y <0.4f) {
// do here
}

Thanks!!! :slight_smile: