Detect falling over in bowling

I’m trying to create a bowling game. I created a pin from a capsule on a cylinder. I parented them and then attached a rigid body to the capsule. My thought was when the pin falls over and collides with the floor then I could detect that it has fallen over. The script does not seem to work however.

Is there a way to see if an object has fallen over?

4 Answers

4

Try finding the Vector3.Dot between the pin's transform.up and Vector3.up! If the dot product is 0, then your pins are standing up, and if it is 1, then your pins have fallen over. No need for collision detection at all! You could even define some threshold point (between 0 and 1) which determines at what point the pins are declared 'fallen'.

I'm thinking that since the dot is always with (0,0,1), the dot-product is always just z. Should be able to use simply: if(transform.up.z<0.5f) to check if your local up isn't very up at all.

yeah good point. What if it was super-gravity space bowling?? ... kidding

You can do a Physics.RayCast coming out the top of the pin.

Then have 4 colliders surrounding where the pins are kept. If your raycast from your pin head intersects any of these 4 colliders, then you know the pin is horizontal.

I tried if(transform.up.z<0.5f) but that did not work, but changing it to if(transform.up.y<0.5f) worked beautifully.

I want to try the Raycast option too, but just because I need to practise that.

Thanks for all your help

Oh, right. Y is up. That's what I get for switching between blender (where z is up) and this.

haha, yeah, gets me every time too... Personally can't understand why the two coordinates you use the most should be X and Z- makes so much more sense in blender.

I tried if(transform.up.z<0.5f) and that did not work, however if(transform.up.y<0.5f) worked beautifully.

Thanks for all your help.

Steve