Rotation Based Activation And Deactivation Code

I was trying to make a script for when my game object (It’s a car) is not standing up it disables the movement script. This was working when the game object is on it’s sides but not when it is upside down. The script is still enabled when it is upside down. Here is my code for detection the rotation on the X axis and disabling the script. The name of my movement script is PlayerMovement.
I tried a lot of fixes but non of them ever worked. -Thanks

public GameObject Car;
public PlayerMovement PlayerMovement;

// Start is called before the first frame update
void Start()
{
    Car.SetActive(true);
    PlayerMovement.enabled = true;
}

// Update is called once per frame
void Update()
{
    float xRotation = transform.eulerAngles.x;



    // Check if the object is upright or upside down
    if (xRotation >= -10 && xRotation <= 10) // Narrowed range for upright
    {
        Car.SetActive(true);
        PlayerMovement.enabled = true;
    }
    else
    {
        Car.SetActive(true);
        PlayerMovement.enabled = false;
    }
    
}
    void Update()
    {
        if (Vector3.Dot(Car.transform.up,Vector3.down)>0.5f) // is the car upside down?
            PlayerMovement.enabled=false;
        else
            PlayerMovement.enabled=true;
    }

This is only working if the car is upside down, It should deactivate the script if it is on its side too. Could you help me with this?

    void Update()
    {
        PlayerMovement.enabled=Vector3.Dot(Car.transform.up,Vector3.up)>0;
    }
1 Like