dotween icon indicating copy to clipboard operation
dotween copied to clipboard

DORotate about X-axis wobbles about X, Y, Z axes

Open Fuzionist1 opened this issue 6 years ago • 43 comments

This is a repost/revision of closed issue #347 because it was closed prematurely. I have updated my explanation with a simpler example that shows there is clearly a bug in the DORotate method.

To reproduce the bug:

  1. Create a New Unity Project (in Unity 2019.2.10f1)
  2. Import the latest version of DOTween Pro (v.1.0.165)
  3. Right Click > 3D Object > Cube
  4. Cube > Transform > Right Click > Reset
  5. Drag CubeRotator onto Cube (see new code below)
  6. Play
using DG.Tweening;
using UnityEngine;

public class CubeRotator : MonoBehaviour
{
    private void Start()
    {
        transform.eulerAngles = new Vector3(95, 0, 0);
        transform.DORotate(
            new Vector3(100, 0, 0), 1);
    }
}

EXPECTED BEHAVIOR: The cube rotates from X-Rotation of 95 degrees to X-Rotation of 100 degrees, and the Y and Z Rotation values stay at 0 the whole time.

ACTUAL BEHAVIOR: The cube rotates from X-Rotation of 95 degrees to X-Rotation of 100 degrees, and the Y and Z Rotations change constantly throughout the tween.

Watch a video here: https://gfycat.com/zealousdisloyalgallinule (when viewing, click the gear icon to switch to HD)

I made posts about my experiments here: https://forum.unity.com/posts/5104151/ https://forum.unity.com/posts/5110205/

ZealousDisloyalGallinule-size_restricted

Previous Response On Issue #347 there was a response from @lordlycastle that the solution was simply to use RotateMode.LocalAxisAdd. This is not a solution.

First, the problem was not the RotateMode. There was no reason why the Y and Z axes should have changed when only tweening the X-Rotation value.

Second, RotateMode.LocalAxisAdd is a different method used for different circumstances. It does not allow you to choose the final rotation angle. It adds to whatever the current rotation angle may be. This is not the behavior I needed, and this does not correct the bug in the DORotate method.

FURTHER COMMENTS My investigations have revealed that the bug described appears to happen only when the starting X-Rotation is greater than 90 degrees - and only happens with X-Rotation (not with Y-Rotation or Z-Rotation).

Example 1 - Rotation-X from 70 degrees to 80 degrees:

using DG.Tweening;
using UnityEngine;

public class CubeRotator : MonoBehaviour
{
    private void Start()
    {
        transform.eulerAngles = new Vector3(70, 0, 0);
        transform.DORotate(
            new Vector3(80, 0, 0), 1);
    }
}

Notice in the video that the X-Rotation tweens from 70 to 80 degrees, while the Y and Z remain at 0 the entire time. This is correct behavior.

Video: https://gfycat.com/recklessdownrightenglishsetter RecklessDownrightEnglishsetter-size_restricted

Example 2 - Rotation Y from 95 degrees to 100 degrees:

using DG.Tweening;
using UnityEngine;

public class CubeRotator : MonoBehaviour
{
    private void Start()
    {
        transform.eulerAngles = new Vector3(0, 95, 0);
        transform.DORotate(
            new Vector3(0, 100, 0), 1);
    }
}

Notice in the video that the Y-Rotation tweens from 95 to 100 degrees, while the X and Z remain at 0 the entire time. This is correct behavior.

Video: https://gfycat.com/kaleidoscopicglaringdormouse KaleidoscopicGlaringDormouse-size_restricted

CONCLUSION The DORotate method has a bug characterized by wobbling in the Y and Z axes when rotating about the X axis starting from an X-Rotation angle above 90 degrees.

Fuzionist1 avatar Dec 16 '19 17:12 Fuzionist1

@Demigiant thought? Curious to know this behavior as well.

My reasoning for previous issues was that when you move from 180, 0, 0 to 0/360, 0, 0 and take FastBeyond360 mode, it does the right behavior where it rotates all axes as that is the fastest way to get to that rotation. I assumed that was only true when you were moving back to 0/ 360; I would not expect this to happen if you moved to 359.

lordlycastle avatar Dec 18 '19 12:12 lordlycastle

Ahoy! Mhmmm that is indeed weird. Testing this out :P

Demigiant avatar Dec 18 '19 12:12 Demigiant

Oh, all clear now. The problem is that the euler value of a Quaternion is not really the same Vector3 value that the Unity inspector shows you (100,0,0 is actually 80,180,180) and in some cases it makes the rotation behave weirdly. This can be solved by using DORotateQuaternion instead, but I'm implementing a fix for the normal DORotate (I already have it working, but since it changes the core system of how rotations work I want to test it out a little bit more).

Demigiant avatar Dec 18 '19 13:12 Demigiant

Hi @Demigiant , if you take a look at my forum posts (links provided above), you will see code and video showing an example where I clicked Flip To Back - rotating X to 180, then I clicked Flip To Back again (which should do nothing because the angle is already 180) and the object wobbles dramatically about all axes. This behavior can likely be reproduced for any X angle above 90. And this behavior is specific to X axis. In fact my temporary fix was to rotate my artwork 90 degrees so I could use DORotate on an axis other than X.

Fuzionist1 avatar Dec 18 '19 13:12 Fuzionist1

The fix I made should fix everything :) Though it's taking me much more to create a comprehensive test (also for Beyond360 and From tweens) than the time it took me to implement the fix :B

Demigiant avatar Dec 18 '19 13:12 Demigiant

Thank you. :)

Fuzionist1 avatar Dec 18 '19 13:12 Fuzionist1

@Demigiant Live a little. If you have no tests, then they cannot fail. 💯

lordlycastle avatar Dec 18 '19 13:12 lordlycastle

Whew, it's more time-consuming than I thought. I have to stop now but I'll continue tomorrow (problem is now from 85 to 100, thought 180 to 180 works correctly) :P The GIF is for the Fast RotateMode.

dotweenRotateTests

Demigiant avatar Dec 18 '19 15:12 Demigiant

Thanks @Demigiant I appreciate your efforts to resolve this. I am a pretty new adopter of DOTween, but I cannot imagine that others have not also faced this issue and will appreciate your work to fix it. Cheers.

Fuzionist1 avatar Dec 18 '19 16:12 Fuzionist1

Just checking to see if there is an update on this. (FYI - I have supported by purchasing DoTween Pro). Thanks!

Fuzionist1 avatar Jan 20 '20 18:01 Fuzionist1

I postponed this in favor of this craziness. I hope using DORotateQuaternion in the meantime is good enough for you, but I'll get back to it asap (sorry for the delay).

Demigiant avatar Jan 22 '20 13:01 Demigiant

@Demigiant Hot Damn! That's whack! Love it. Would be possible to do callback through UI as well?

It would be kewl if it can generate the code too.

I had some performance question, where should I ask them?

lordlycastle avatar Jan 22 '20 15:01 lordlycastle

It will definitely allow callback within the UI but will not generate code :P

About performance, open a new issue and I'll check it within the day, promised! :)

Demigiant avatar Jan 22 '20 16:01 Demigiant

Thanks for the update. And that graphical UI looks awesome.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Daniele Giardini [email protected] Sent: Wednesday, January 22, 2020 11:20 AM To: Demigiant/dotween Cc: Fuzionist1; Author Subject: Re: [Demigiant/dotween] DORotate about X-axis wobbles about X, Y, Z axes (#353)

It will definitely allow callback within the UI but will not generate code :P

About performance, open a new issue and I'll check it within the day, promised! :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Demigiant/dotween/issues/353?email_source=notifications&email_token=ADE76CNSDI4BDYNJKL7F6VLQ7BW3PA5CNFSM4J3NEEHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJUF52I#issuecomment-577265385, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADE76CNXXHYMALMLP2YWGETQ7BW3PANCNFSM4J3NEEHA.

Fuzionist1 avatar Jan 22 '20 21:01 Fuzionist1

+1 for this issue. I thought I was completely losing my mind until I came across this.

I'm not sure if DoRotateQuaternion is an adequate workaround - it seems to behave differently than my other rotate tweens, at least with regard to speed (I'm using .SetSpeedBased() - does DoRotateQuaternion support that?). Maybe I could convert all of my rotation tweens to quaternions so the speeds would be unified just so this one wouldn't be broken, but then it seems like calculation for all their angles would be more difficult, since most times I'm using simple manipulation of euler angles to get my rotations.

Crossing my fingers for a fix in the near future :)

jmdodge avatar Feb 21 '20 08:02 jmdodge

As soon as I'm done with the Timeline I'll get back to this. I already have nightmares :P

Demigiant avatar Feb 21 '20 09:02 Demigiant

@piyushradadiya lol.... dat quote dough! 🍞

lordlycastle avatar Jun 15 '20 01:06 lordlycastle

I've been following this thread recently, and waiting for it to get solved. @Demigiant Do you have any update on this? Also if there is any workaround for it?

Thanks

shravanvavadiya avatar Jun 15 '20 06:06 shravanvavadiya

Ahoy! I postponed this more and more in favor of other things (but at times tried a couple other solutions but they didn't work), I apologize (last new thing that "ate" this one is a way to tween TMP texts per-character including skew/scale/shift, so pros and cons I hope).

The current workaround is to use DORotateQuaternion instead (will add it to the docs until I fix this):

transform.eulerAngles = new Vector3(95, 0, 0);
transform.DORotateQuaternion(Quaternion.Euler(new Vector3(100, 0, 0)), 1);

Demigiant avatar Jun 15 '20 11:06 Demigiant

Yay! That worked. Thanks for the help!

shravanvavadiya avatar Jun 16 '20 07:06 shravanvavadiya

@Demigiant Hi hope you'll have some time to dig into this issue again.

Until then I wish you all the best. Stay safe and healthy ...happy holidays.

mmeiburg avatar Dec 19 '20 08:12 mmeiburg

i know its very late, but i had the same problem. used transform.DOLocalRotate(Vector3 , 1);

violeDgrace avatar Mar 03 '22 20:03 violeDgrace

Hi @Demigiant , I am also facing the issue for Do Local Rotate. Every time I try to align using do tween the destination keeps changing.

  private Tween GetRotateTween(AnimData data)
  {
      var curretAngle = data.targetMesh.localRotation.eulerAngles;
      return data.targetMesh.DOLocalRotate(new Vector3( data.xAngle,curretAngle.y,curretAngle.z) , data.time);
  }

I want to rotate the mesh to a fixed angle in its local axis but the result is not as expected at all times. It rotates beyond the desired angle sometimes. Please resolve this ASAP 🙏

Rohith-Nanthan avatar Mar 16 '22 18:03 Rohith-Nanthan

@Demigiant , I also tried Do local Rotate Quaternion but it still doesn't work 😢

    private Tween GetRotateTween(AnimData data)
    {
        var curretAngle = data.targetMesh.localRotation.eulerAngles;
        return data.targetMesh.DOLocalRotateQuaternion( Quaternion.Euler(new Vector3( data.xAngle,curretAngle.y,curretAngle.z)) , data.time);
        //return data.targetMesh.DOLocalRotate(new Vector3( data.xAngle,curretAngle.y,curretAngle.z) , data.time);
    }

Rohith-Nanthan avatar Mar 16 '22 19:03 Rohith-Nanthan

Ouch, DOLocalRotateQuaternion not working makes this an emergency. On it during this week, sorry!

Demigiant avatar Mar 21 '22 09:03 Demigiant

Whew. Ok I'm tapped out (spent all week working on this, and all this morning making tests). This new version (1.2.675) fixes the problem with RotateMode.Fast, but still has the same problem with RotateMode.Beyond360 and from/relative tweens. I will get to those later but for now it's the right replacement for DORotateQuaternion not working correctly (or better: working correctly in Unity's Quaternion space but not in what one usually wants as an actual result)

Demigiant avatar Mar 25 '22 12:03 Demigiant

Hi, Thanks for pushing the update in the short time I really appreciate it. I tested the new build and unfortunately it still doesn't resolve DoLocalRotate with RotateMode.Fast or with DoLocalRotateQuartenion 😢

Rohith-Nanthan avatar Mar 25 '22 21:03 Rohith-Nanthan

What?!? Agh! But! I made tons of tests with various kinds of starting and ending rotations, noooo :( So sorry, I thought I had at least fixed this side of it. Could you post me a sample code with the actual starting rotation and final rotation you're using (or even better, a small package that replicates it), so I can test against your case directly?

Demigiant avatar Mar 25 '22 21:03 Demigiant

Victory! This update (v1.2.680) fixes the wobbling with all methods, including From. I'm leaving the issue open while I test it even more, but with all my tests (including yours, @Rohith-Nanthan) everything works.

Demigiant avatar Apr 02 '22 11:04 Demigiant

Thanks @Demigiant . I appreciate you getting around to this.

Fuzionist1 avatar Apr 02 '22 11:04 Fuzionist1