Multiply 2 quaternions with Visual Scripting

I’m wanting to rotate a rigidbody by a certain amount per frame using Visual Scripting.

The way you do this in c# is something like this.

    Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.fixedDeltaTime);
        m_Rigidbody.MoveRotation(m_Rigidbody.rotation * deltaRotation);

However, I cannot see a way to multiple 2 quaternions together. Is there something I’m missing or an alternative way to rotate a rigidbody.

Hello there,

I did not find a multiply unit for Quaternion (I’m not sure why there is no such unit) but you can use the generic multiply unit (Math/Generic/Multiply)
9446651--1325615--upload_2023-11-2_16-57-41.png

Something like this should work:

Another solution is just to create a custom unit to multiply two quaternions together (derived from the native Vector4Multiply unit). And you can also create another custom unit to multiply a scalar with a Vector3.

using UnityEngine;

namespace Unity.VisualScripting
{
    /// <summary>
    /// Returns the product of two quaternions.
    /// </summary>
    [UnitCategory("Math/Quaternion")]
    [UnitTitle("Multiply")]
    public sealed class QuaternionMultiply : Multiply<Quaternion>
    {
        protected override Quaternion defaultB => Quaternion.identity;

        public override Quaternion Operation(Quaternion a, Quaternion b)
        {
            return a * b;
        }
    }
}

9446651--1325630--upload_2023-11-2_17-6-0.png

1 Like