Detecting if a gameobject is not standing up.

Hey everyone, I’m trying to check to see if an object is standing up. for some reason when I imported my model from blender and I put it into the game, the roation has to be -90 in the X direction in Unit for the object to be “Standing up” so I figured okay cool no problem, make a child object and just set its rotation to 0 across the board and get the localroation of that. However it is still getting the transform of the parent and returning the 270 degrees when its standing up. Is there a way I can code around this? I tried to find a fix for it a different way and have come up empty handed. Heres the code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pins : MonoBehaviour {
    public float standingThreshold = 3f;
    // Use this for initialization
    void Start () {
    }
  
    // Update is called once per frame
    void Update () {
        print(name + IsStanding());
    }

    public bool IsStanding()
    {
        Transform tiltSensor = GetComponentInChildren<Transform>();
        Vector3 RoatationInEuler = tiltSensor.localRotation.eulerAngles;

        float TiltInX = Mathf.Abs(RoatationInEuler.x);
        float TiltinZ = Mathf.Abs(RoatationInEuler.z);
        print(TiltInX + "" + TiltinZ);

        if (TiltInX < standingThreshold && TiltinZ < standingThreshold)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

You could just load it up in blender, rotate it in there remembering that ion blender the Z axis is up.

Once you have it facing up on the Y axis, press Ctrl + A in object mode and select rotation.

Export it again and all will be well.

1 Like

Heres the problem, it already is standing upright in blender. I checked that. I even went to the extend of rotating it in blender and then re importing it and it just made the entire model that way instead of just the collider.

In blender using the FBX exporter options there should be a tick box for set y = up. I recommend using the FBX and not letting unity just read form the .blend.

1 Like

It’s not standing up. Look in the corner, Z axis is up in blender, Y axis is up in Unity.

If you are stuck, feel free to pm me a link with the models and I’ll fix them for you.

1 Like

Hey guys I appreciate your help! Even though this happened to be more of a blender fix than the code. I did as Jaxom recommended and used the FBX export options to change the way the model was exported and all is well!

I must’ve rotated it incorrectly when I tried to do it manually in blender the first time. Either way, code works flawlessly now and I have no weird rotation to make my objects stand up. Thanks!

I guess the way I was thinking about the exporting last night, I figured if it was upwards in blender, it would translate that to being upright in unity.