Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lockRotation has no effect with DOPath & SetLookAt #167

Closed
mrtenda opened this issue Nov 3, 2017 · 23 comments
Closed

lockRotation has no effect with DOPath & SetLookAt #167

mrtenda opened this issue Nov 3, 2017 · 23 comments

Comments

@mrtenda
Copy link

mrtenda commented Nov 3, 2017

Hello, I am trying to use DOPath and SetLookAt to traverse the camera along a path while keeping the camera looking at the hero. Here's the code I am running:

transform.DOPath(wps, 2, PathType.CatmullRom, PathMode.Full3D)
.SetOptions(false, AxisConstraint.None, AxisConstraint.Z)
.SetLookAt(Hero.transform);

However, despite specifying a locked rotation axis constraint of Z, the transform still rotates on the Z axis during the tween. The starting rotation for the transform is shown as (20, 0, 0) in the Unity inspector, and the final rotation for the transform at the completion of the tween is shown as (139.238, -1.85199, 104.181).

Is this the expected behavior? If so, what would the correct way to do this be? Thanks.

(I am using DOTween Pro if that's relevant)

@Demigiant
Copy link
Owner

Hi,

I made some tests but everything seems ok here. Are you sure the transform is rotating around the Z axis? The fact that the euler Vector3 Z value changes, doesn't mean it's truly rotating around Z, since that is just a conversion from Quaternion, and the resulting euler isn't indicative.

Cheers,
Daniele

@mrtenda
Copy link
Author

mrtenda commented Nov 24, 2017

Thanks, the issue was that I assumed that it was rotating around the euler axis, not a quaternion axis. For anyone reading this in the future who is curious, I ended up achieving the effect I wanted by just doing DOPath simultaneously with DORotate in a sequence:

Sequence sequence = DOTween.Sequence();
sequence.Append(transform.DOPath(wps, 2, PathType.CatmullRom, PathMode.Full3D));
sequence.Join(transform.DORotate(rotationFromLastWaypointToHero, 2));

@mrtenda
Copy link
Author

mrtenda commented Mar 4, 2018

Hey, I'd like to revive this thread, as my workaround in my previous comment of just using a simultaneous DOPath and DORotate won't work anymore for a situation I'm dealing with now.

I am trying to use DOPath on my camera's transform to move the camera along a path in order to show an establishing shot of the scene. The issue I am facing once again is that when I use SetLookAt with DOPath on my camera's transform, DOTween rotates the transform using all of its Euler axises, including the Z axis. It is highly undesirable to rotate the camera on its Euler Z axis, since doing so has a disorienting effect on the player. I have tried using the lockRotation parameter of SetOptions to solve this problem, but this seems to have no effect, no matter what combination of AxisConstraints I specify in lockRotation (including if I specify all of the axises).

Is there any possible way to use SetLookAt together with DOPath while locking the Euler Z rotation axis? If not, is there another way you would suggest that would let me accomplish what I'm trying to do here? Thanks for the help.

@Demigiant
Copy link
Owner

Uhm that is weird. Can you send me a screenshot of your path so I can check it out?

@Demigiant
Copy link
Owner

P.S. Also, can you show me your DOPath code?

@mrtenda
Copy link
Author

mrtenda commented Mar 4, 2018

Thanks for the quick reply. I went ahead and created an example standalone Unity project that showcases the behavior I'm talking about.

dotween_path_lookat_z.zip

(Import the asset package in the above zip into a brand new Unity project, then play the included scene and press the space bar to start the path. Created/tested with Unity 2017.1.0f3 and it includes DOTween v.1.1.695)

Here's what it looks like in action:

dotween_path_lookat_z

As you can see in the Game view and the Inspector, DOTween is rotating the Camera's transform on the Euler Z axis, resulting in a tilted view of the world (easily seen by the fact that the skybox's horizon is tilted).

Thanks again, and let me know if I can provide any more information.

@sokigakiya
Copy link

Hi, I'm having the same trouble

I have this code

Vector3[] waypoints = new[] { new Vector3(33f, 40f, 0f), new Vector3(32.8f, 40.7f, 0f), new Vector3(32f, 41f, 0f), new Vector3(31f, 41f, 0f) };

_playerRigidBody.transform.DOPath(waypoints, 5, PathType.CatmullRom, PathMode.Sidescroller2D, 5, Color.cyan).SetOptions(lockPosition: AxisConstraint.Z).SetLookAt(new Vector3(32, 40, 0));

On a 2D game, and my game object rotates the X and Y axis, so the sprite dissapears, this happens even if I place the lockRotation X and Y axis, so it's not rotating around the Z axis, tried with code and with the visual path editor, same results, is this a bug?

Thanks

Soki

@sokigakiya
Copy link

I just noticed, it seems to be swapping the axis

So instead of rotating around Z, it rotates around X, Z and Y get swapped between them

Thanks

Soki

@sokigakiya
Copy link

So I was able to get it to work by specifying the forwardDirection as Vector3.right (?!) and up vector as Vector3.Forward, this is really confusing, only thing is when the path is done, it still changes the rotX and rotY, it kind of works, but sometimes I end up with weird XYZ values...

@Tommie0607
Copy link

Heyhey,

@Demigiant @mrtenda @sokigakiya

I had the same problem as you guys so I decided to look at the source code :)
I think I found the bug.

In Pathplugin.cs, SetOrientation the rotation is set for the animating object.

switch (options.orientType) {
            case OrientType.LookAtPosition:
                path.lookAtPosition = options.lookAtPosition; // Used to draw editor gizmos
                newRot = Quaternion.LookRotation(options.lookAtPosition - trans.position, trans.up);
                break;
            case OrientType.LookAtTransform:
                if (options.lookAtTransform != null) {
                    path.lookAtPosition = options.lookAtTransform.position; // Used to draw editor gizmos
                    newRot = Quaternion.LookRotation(options.lookAtTransform.position - trans.position, trans.up);
                }
                break;

For the up-vector in the Quaternion.LookRotation you're using the up of the object you're animating, while to achieve the effect we want you should use the up of the world (Vector3.up)
This at least fixed it for me :)

You can download the source-code, change it yourself and rebuild the dll or try my build version from the link :) (I didn't manage to recreate the mdb file so unity will give an error about a non-matching symbol file but you can just ignore that)
http://www.studiowaterzooi.com/dotweensetlookatfix.zip

Cheers!
Thomas

@Demigiant
Copy link
Owner

Ahoy!
Sorry if I stayed out of this issue, but I was always derailed by some other feature/fix, and Quaternions are my personal hell :B
@Tommie0607 thank you very much for the contribution. Did you simply change trans.up to Vector3.up in those 2 lines and that's it? I will implement it in the source code, though I'll have to think of a logical way to do it (because trans.up is indeed needed for all other occasions).

@oalpha
Copy link

oalpha commented Apr 23, 2018

I'm having the same trouble too!

@jamestillercode
Copy link

I am also having this issue. Is there a way to add features to DOTween, like a LookAt extension that resolves this issue? I'd really love to be able to go in and just correct the issue myself.

@zkkzkk32312
Copy link

Also having this issue,

var s = DOTween.Sequence();
s.Append(target.transform.DOPath(wayPointsArray, duration, pathType, pathMode)
.SetOptions(AxisConstraint.None, AxisConstraint.X | AxisConstraint.Z)
.SetLookAt(lookAt.position));

by the end of DoPath,
the target's rotation'X and rotationZ are both changed.

@OmarVector
Copy link

Any official Fix?

@mrtenda
Copy link
Author

mrtenda commented Feb 6, 2019

It seems like a lot of people have been struggling with this since I first opened this issue. I have no idea if an official fix will happen (or has already happened?), but I managed to work around this problem a while ago by using DOPath and then independently also updating the Transform's rotation on every Update to rotate towards the target.

However, if you're dealing with this problem because you're using DOTween on a camera (like I was), I highly suggest not using DOTween at all for camera movement and instead using Cinemachine (which is free and included with Unity). DOTween is a great tool but Cinemachine is built especially for cameras, so it's perfectly suited for this kind of thing (and has many other camera-specific capabilties too).

@Tommie0607
Copy link

Tommie0607 commented Jul 15, 2020

@Demigiant hehe I commented on this more than 2 years ago, didn't use DOTween anymore until now, downloaded it again because I do think its great, found out issue is still there...

@Demigiant
Copy link
Owner

I am so ashamed. I did so many other things in order to avoid this, because I couldn't find a nice way to implement it and it's my personal hell. But now I did it. I'm not superhappy but I simply added an overload to SetLookAt where you can set a "stableZRotation" parameter to TRUE and it will use your fix :B Get it here :P

@Haapavuo
Copy link

stableZRotation fixed it for me. Thank you!

@Mykey05
Copy link

Mykey05 commented Sep 10, 2022

@Demigiant have you released an official fix? If not can you make the above zip available again? The link has expired.

@Demigiant
Copy link
Owner

Ahoy! This had been released already, but you can get the latest version here which I just uploaded (coming in a few days to the Asset Store too)

@Mykey05
Copy link

Mykey05 commented Sep 12, 2022

Much appreciated. 👍

@Mykey05
Copy link

Mykey05 commented Sep 13, 2022

@Demigiant I'm guessing your fix was only for the overload? Because I can't see anything changed in the DoTweenPath component
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants