How Do I Check An Objects Rotation?

I want to have a particle system play when a box is tilted to give off the illusion that dirt is being spilled.

Any ideas?

That sounds pretty complex!

If you’d just like to check an object’s rotation… You’ll need a GameObject reference. You can then use another node to get the transform, and then the rotation of that GameObject.

Here’s how to look up nodes in the graph: Udon Node Graph

But you’d also need to compare that rotation against the upward direction of the world, then see if that angle goes over some threshold, which would enable the particle system…

Not trivial! But I’m sure as you get more familiar with Udon you’ll figure it out :slight_smile:

I tried that. I think I get tripped up when I’m trying to compare the angle.

Basically, I want the particle to start when the object is tipped.

Oh OK! Well, that requires… math!

Here’s an alternative approach: Compare the up vector of the transform to the up vector of the world. There should be a built-in function to compare angles. If the up vector differs too much from Vector3.up, play the particle system!

I hope this can help you get started.

Thank you! Would you mind sending a screenie, as I did mess around with that already?

Just executing it wrong.

Here is an example that I think is what you’re looking for in both Udon Graph and UdonSharp:

Udon Graph:

application/vnd.unity.graphview.elements AO1a21LjRhD9FUrPHtfcL1Ttwy672aJSSajl8pKlXHMTOBESkeVNCMuX5SGflF9IS74AtjAKYNZstuABjWxNT58+3adb/PPX35fJJ5uNY7L982WSjrPsR3sGF8mRLYfWZXGwfzGq4tn+MD/JYtJLxsMAdznjNLWCIUW0RZx4hqwzFGniqfJMapUa+PB5MRpWwyJPti+TP5JtRLHRfaa5kkJS0UsuYE1q0qcYS82EYUpc9ZK8CPFw9+0ITErgIde/x70kzYrfp/eOJ588qq0fNeaP82F18ZP7JfrqaHKmy2SYjyqb+7j7NtnG8PBRVcJRpreT5Kr3kK9NfNLfbxZ7W2cjX5TZ0PW2jmI5gvO+4n1c//S2dsZZNS7jqzyOq9Jmva29scuG/vt4cVD8GvNXTikrvJDEMB6xNp/3z4dZ9rp29sFpGUenRRYeZ+SbosiizZ/WyoMSttg8s76z2eiRdq0D07zIwarj2q42hh3Wtr7LT4Z5PChtPkqL8mzONKu5SWOqkExlQDzlFFktJCKOsBiM1pKrb0x7CCrV3NdfZSBvql1fgGCTnacOuWaWC9SQVCIJrAJmhR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qyiU2Lx2bLkPVp8LmeWV9JwGyBDrTekHVywZvQqGs1gLpLlF/fwVflknBeU+0IyjYACYagMAYhZGklDOgDOSt8CQaafOk/6NHwnepsqm2msiyd7+NbQZPXhBeC1d3qLIu0nc5gCRdltnqnhjqkp8aQfagMHshIntTZ4OdKgypkaqH2pA6AEEHUeOkh5KHIzY+wD3TIs2ghVwOFmr0VyTMOk37nyoD3PnyAbLBXmYvWusEEdpHawOymHuwUAOnYsSISSUgCUtrYks7PZ2gUqYYhu9MsSONqF6hDrrEScP0jZv/PCfFVuG4X0Feb8MRcEi9pR6Ef51EKY3QHQUAk4QUGiRPjcddcaRCrG6hO+L4HMPShelQJ02xXLVEy3SIaLLaCw9TPR0J1wnPF1LbVgT4ERhalAwi+/VkRLR8r22p/f/8ukx22iYEWrVMCCjW97Q6vURD422NUMjhelfQ2yCyTUSSuNQ7pzG0v2vhwQ2X9Kc+6W3dXNwpyvhDEcb1sGaGI+6KYw5Qfb78mPzxEfaGL3xMLuAv0vz152Tt6oHp9EsYjhcMXxGO8xdQ09dU4/O2iLx+md8B/5aAk6CStcJKQ/rllGg9n3vQ+n0+hfyrxXLAdZmxrC3rHl/9Cw==

UdonSharp:

using UdonSharp;
using UnityEngine;

public class DirtBox : UdonSharpBehaviour
{
    [SerializeField]
    private float spillAngleThreshold;

    [SerializeField]
    private ParticleSystem particles;

    private bool isSpilling;

    private void Update()
    {
        if(isSpilling != Vector3.Angle(Vector3.up, transform.up) > spillAngleThreshold)
        {
            if (isSpilling ^= true)
            {
                particles.Play();
            }
            else
            {
                particles.Stop();
            }
        }
    }
}
1 Like

Ohhh @Varneon you’re being too nice! :grinning_face_with_smiling_eyes: Good job.

Yeah @jforceg this is what you’re looking for. Though I’d encourage you to try and understand the code so you can learn from it!

1 Like