I kept getting “false” returns for all of my pins with Ben’s code, seems like I did something wrong, but couldn’t see what. Changing the threshold never helped as the tilt was always within 1degree. After print out the values I noticed tiltInX was usually between 359 and 360, and tiltInZ was between 0 and 1 or 359 and 360. I also assumed that tiltInX could also sometimes be between 0 and 1. So i changed the If statement to reflect the values I was getting and it works perfectly to set IsStanding to true or false now:

If anyone see where I might have went wrong, let me know, and I hope this code might help anyone that cant get theirs working properly.
2 Likes
Hi @darkokubra,
nice solution. I had problems as well, but in the process of deleting and redoing stuff, it looked like it got fixed. I think this is an issue inside Unity. I’m not actually saying that is a bug, but it’s something that is quite annoying.
The problem is that, like other 3d programs using rotations, 0 degrees and 360 degrees are the same. In example, I had problems with the Animator, when in a clip I tried to set 360 as a rotation, automatically the editor set 0 degrees. The only way I found to fix this was to modify the graphic curve in the animation window.
So, I don’t think that is something that you did wrong, but something that can happen and Unity doesn’t solve always the same way. I had the same problem than you, when Ben was getting -3 degrees, I was getting -357 or so. Numerically really different.
Your solution looks quite neat.

1 Like
Yeah this sees to work well. I’m not sure if its because I modeled my own pins, I noticed in a later lecture that when the nested bowling pin was reduced to a single gameobject that Ben’s ended up on its side, mine stayed upright so obviously I didn’t need to change any code to continue counting the pins correctly. Now i just have to get my ball to not slow down as much, or actually fly straight through the pins without actually moving them lol.
Thank you so much for posting this code. For some reason, even though I copied Ben’s code it kept on saying false even though all my pins were standing. Your code fixes the problem.