Obi Official Forum
Bug / Crash Rod dynamic attachment is broken - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Bug / Crash Rod dynamic attachment is broken (/thread-4532.html)



Rod dynamic attachment is broken - Qriva0 - 08-08-2025

Hi, when rod is attached in dynamic mode and constraint orientation is enabled, then the whole attachment becomes broken. To be precise the orientation taken into account is flipped and rod tries to keep opposite direction. This bug can be sometimes not obvious, because when rod is rotated it gets apparent stability for short time.
To reproduce, simply create box with rigidbody (can be frozen and kinematic for particles for better result) and create dynamic attachment with constrained orientation.

I want to not that it's best if box and rod is perfectly aligned and not rotated.
Attached image shows my setup before and several frames after starting simulation.

Obi 7.1
Unity 6000.0.54


RE: Rod dynamic attachment is broken - josemendez - 11-08-2025

(08-08-2025, 06:07 PM)Qriva0 Wrote: Hi, when rod is attached in dynamic mode and constraint orientation is enabled, then the whole attachment becomes broken. To be precise the orientation taken into account is flipped and rod tries to keep opposite direction. This bug can be sometimes not obvious, because when rod is rotated it gets apparent stability for short time.
To reproduce, simply create box with rigidbody (can be frozen and kinematic for particles for better result) and create dynamic attachment with constrained orientation.

I want to not that it's best if box and rod is perfectly aligned and not rotated.
Attached image shows my setup before and several frames after starting simulation.

Obi 7.1
Unity 6000.0.54

Hi,

Quaternions q and -q represent the same orientation. This means that an attached object may flip 180º degrees and consider this its new rest rotation if rotated away from the original rest pose.

The simplest workaround is to create 2 attachments instead of one. This removes aliasing between orientations 180º degrees apart from each other.

kind regards


RE: Rod dynamic attachment is broken - Qriva0 - 11-08-2025

(Today, 09:39 AM)josemendez Wrote: Hi,

Quaternions q and -q represent the same orientation. This means that an attached object may flip 180º degrees and consider this its new rest rotation if rotated away from the original rest pose.

The simplest workaround is to create 2 attachments instead of one. This removes aliasing between orientations 180º degrees apart from each other.

kind regards

I am confused, how/why quaternion gives the same orientation while it's pointing the opposite direction? I think I am missing something.
Also it's not problem with rotation of that object - it's problem with rotation of rod particle, because cube in my case is kinematic for particles.
The workaround does not work, it makes rod wiggle like crazy, then randomly stops for a moment when it becomes more stable for several seconds (see attached image).

I think dynamic attachment calculates quaternions/matrices incorrectly, because static attachment works correctly (custom script as well).


RE: Rod dynamic attachment is broken - josemendez - 11-08-2025

(Today, 10:20 AM)Qriva0 Wrote: I am confused, how/why quaternion gives the same orientation while it's pointing the opposite direction? I think I am missing something.

Quaternions don't really "point in a direction", since they're not vectors in R3. A quaternion and its negative counterpart represent the exact same orientation. For an explanation and proof, see: https://math.stackexchange.com/questions/2016282/negative-quaternion



(Today, 10:20 AM)Qriva0 Wrote: Also it's not problem with rotation of that object - it's problem with rotation of rod particle, because cube in my case is kinematic for particles.

That makes no difference whatsoever: if two objects A and B are attached, rotating A 45 degrees or B -45 degrees results in the same relative rotation between both. If you statically attach the particle and then make the cube non-kinematic, the cube will rotate instead.

(Today, 10:20 AM)Qriva0 Wrote: The workaround does not work, it makes rod wiggle like crazy, then randomly stops for a moment when it becomes more stable for several seconds (see attached image).

Make sure the two attachments don't attach the same control point twice. That leads to undefined behavior as stated in the manual:

Quote:Particles affected by more than one attachment will follow the attachment that was updated last. The update order for attachment is undefined.

By two attachments I meant one attachment to one control point, and a second attachment to a different control point close to the first. This works because infinite lines pass trough one point in space, but only one line passes trough two points. This removes the ambiguity in quaternion rotation.

(Today, 10:20 AM)Qriva0 Wrote: I think dynamic attachment calculates quaternions/matrices incorrectly, because static attachment works correctly (custom script as well).

A static attachment doesn't have this issue because it doesn't involve physics of any kind. A new quaternion is not derived from physical calculations (which are ambiguous because of the aforementioned issue with rotations 180º degrees apart from each other), it just copies the attached object orientation to the particle.

kind regards,


RE: Rod dynamic attachment is broken - Qriva0 - 11-08-2025

(Today, 10:30 AM)josemendez Wrote: Quaternions don't really "point in a direction", since they're not vectors in R3. A quaternion and its negative counterpart represent the exact same orientation. For an explanation and proof, see: https://math.stackexchange.com/questions/2016282/negative-quaternion

Actually you are right. What my dumb brain meant by minus is inversed quaternion. I know quaternion does not point towards any direction, but the way the rod works I expected particle to keep rotation relative to attached object.

(Today, 10:30 AM)josemendez Wrote: Make sure the two attachments don't attach the same control point twice.

This is what I did, I have two different control points attached to that cube, next to each other.

(Today, 10:30 AM)josemendez Wrote: By two attachments I meant one attachment to one control point, and a second attachment to a different control point close to the first. This works because infinite lines pass trough one point in space, but only one line passes trough two points. This removes the ambiguity in quaternion rotation.

To be honest I still don't understand why this does not work. My sense is that quaternion of particle A has some rotation, but because it's driven in different way than static constraint it can get negative quaternion? and because this gives the same orientation, then when it's lerped or weighted or whatever happens there it starts to go crazy? and it only happens when both orientations are aligned? Why it becomes stable after flipping?

In any case I don't understand why it's always opposite direction, for example if I rotate cube by 10 deg, then this is what I get, and it's still unstable.


RE: Rod dynamic attachment is broken - josemendez - 11-08-2025

(11 hours ago)Qriva0 Wrote: My sense is that quaternion of particle A has some rotation, but because it's driven in different way than static constraint it can get negative quaternion? and it only happens when both orientations are aligned? Why it becomes stable after flipping?

All a static constraint does is particle.rotation = transform.rotation. It cannot flip because it doesn't operate on the quaternions at all, it's literally just a copy.

A dynamic constraint on the other hand assumes the rotation of the particle and the transform are different. It calculates the minimum orientation that would turn the rotation represented by quaternion A (particle's rotation) into the rotation represented by quaternion B (transform's rotation), then use it to calculate the torques it must apply to both of them in order to get their orientations to match. The problem lies in the way the torques are calculated, if quaternionA =-quaternionB the orientations represented by them already match and the calculated torques are zero. This is why it flips and then becomes stable.

In any case, this should be prevented by using two attachments. Can you share a sample scene that reproduces this by sending it to support(at)virtualmethodstudio.com? This way I can check if there's something else going on.

kind regards,


RE: Rod dynamic attachment is broken - Qriva0 - 11-08-2025

(11 hours ago)josemendez Wrote: In any case, this should be prevented by using two attachments. Can you share a sample scene that reproduces this by sending it to support(at)virtualmethodstudio.com? This way I can check if there's something else going on.

Sure, I will try to create package with simple scene.