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;
}
}
}