Pins standing check error

Hi.

I can’t seem to get the check for pin standing to return correctly.

After a few seconds running most of my pins return a false value for the standing check

Debugging Pin 1 is showing a tiltZ value of 359.98 when I’d expect to see -0.02 which would then be an absolute value of 0.02 and would then return true. This is showing in the rotation value of the inspector but isn’t returned by the eulerAngles.

I’m using Unity 2017.3

My code:

public bool IsStanding() {

    Vector3 rotationInEuler = transform.rotation.eulerAngles;

    float tiltX = Mathf.Abs(rotationInEuler.x);
    float tiltZ = Mathf.Abs(rotationInEuler.z);

    if (statusDebug) Debug.Log("xtilt: " + tiltX + " ztilt: " + tiltZ);

    if (tiltX < standingThreshold && tiltZ < standingThreshold) {

        return true;
    } else {
        return false;
    }
}
1 Like

I also have this problem. All three axes have strange rotations on them that are constantly changing. Haven’t figured it out yet but I think it’s related to the scaling of all the objects in the game being much higher than reality.

So I’ve ignored this script and copied the script given by @bendman in this post (use the second one as this ignores the y variable). This works flawlessly so far.

A few lessons later on Ben changes the structure of the pins so that they are out by 270 degrees (and you have the fun of recreating all of the pins again!) when this happens the code doesn’t work so I have added the line

eulerWithoutTwist -= new Vector3(270, 0, 0);

this goes in after the 1st line and will adjust the X by 270 so that it is checked against 0 (if this bit doesn’t make sense right now it will in a few videos time when Ben breaks stuff :wink: )

3 Likes

I was going to post a code snippet up for your original question Martyn, but I noticed that what I had included the 270 change, and I didn’t want to send you down a path of pain… before it came up in the course… :wink:

1 Like

Marc shared his code with me when I first posts to discord. Neither of us could understand the -270 he had either. Not going to lie, I cried a little when I realised we had to redo the pins as I’ve now re-done them about 7 times because of issues with prefabs getting deleted.

I still don’t understand though why my initial code doesn’t work correctly as described in the lecture. I recreated the same issue in Unity 5 so it doesn’t seem like a version variance and I had a brief look at the version history of .eulerAngles and couldn’t see it having changed majorly with an update.

2 Likes

I cried a little when I realised we had to redo the pins as I’ve now re-done them about 7 times because of issues with prefabs getting deleted

Ouch! I think you have just earned the title, “Person to contact for all Bowlmaster related issues” :wink:

I still don’t understand though why my initial code doesn’t work correctly as described in the lecture.

The answer may not lay in the code, it could be something very subtly different in the Inspector for a GameObject etc.

If you wanted to check your code line for line, you could check the GitHub repositories to look for differences I suppose, but unless it’s really troubling you, I’d probably just keep moving forward.

You could always create a more simple scene, apply your code to a different object in a different scene etc, that way you could remove a lot of the complexity from the main game to try and work it out.

Bowlmaster was a very long section, so kudos for continuing with it and working your way through. :slight_smile:


See also;

I’m pretty sure there’s forum rules against me typing my thoughts to that ha so I’ll just say no thank you :rofl:

If you wanted to check your code line for line, you could check the GitHub repositories to look for differences I suppose, but unless it’s really troubling you, I’d probably just keep moving forward.

Fair enough. I sounds like adjustments via quaternions are the better solution for this sort of thing anyway so I’ll probably spend time learning how those work rather than worrying about the variance for one solution. Time to spend time learning maths, wooo!

1 Like

Privacy & Terms