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?
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.
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.
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'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:
– Owen-Reynoldsif(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
– syclamoth