Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.35k stars 350 forks source link

DOPath moves very quick #430

Closed emrys90 closed 4 years ago

emrys90 commented 4 years ago

I'm having an issue where DOPath moves extremely quick, even though I have duration set to a long time. My assumption is that because I'm dealing with small units, its assuming that its reached the waypoint and skips it and moves on or something. Is there anything I can do to resolve this?

emrys90 commented 4 years ago

Actually, the issue is due to it being in a sequence. If I remove it from the sequence then it plays at a normal speed. What do I need to change to resolve that?

Demigiant commented 4 years ago

Ahoy!

It's very weird that it behaves differently if inside a Sequence, could you show me your Tweener+Sequence code VS your Tweener-only code?

Also, if you chain a SetLookAt you can decide how the path lookAt will behave.

emrys90 commented 4 years ago
                    var path = new [] { midPoint, a, b, position, midPoint, d };
                    Sequence sequence = DOTween.Sequence();
                    _tween = sequence;

                    var pathTween = this.transform.DOPath(path, _moveSpeed, PathType.CubicBezier)
                        .SetSpeedBased()
                        .SetEase(Ease.Linear)
                        .SetOptions(AxisConstraint.None, AxisConstraint.X | AxisConstraint.Z)
                        .SetLookAt(0.1f)
                        .OnComplete(() => RotateTo(rotation));
                    _tween = pathTween;
                    sequence.Append(pathTween);

It's a drastic difference in speed when in a sequence, and no matter what I set the speed to it doesn't seem to affect it.

I do have a SetLookAt call in, but is there a way to have it wait to rotate to face it rather than immediately facing it on the start of the path? IE If I have an object that starts a path going backwards, it instantly does a 180 degree turn.

For the tween only code, I just comment out creating the sequence and appending the tween.

Demigiant commented 4 years ago

Ah, the problem there is that SetSpeedBased doesn't work in nested tweens (because a Sequence needs to know every nested tween's duration when you add it, and speedBased ones are evaluated when they start). So you should either keep it outside the Sequence or calculate the duration manually.

About the "slow lookAt" there is no built-in way, but you could use pathTween's OnUpdate to make a manual Lerp to the actual direction (OnUpdate is called AFTER your transform's position/rotation has been updated by DOTween, so you could have the previous position stored, Lerp to the one DOTween set, and restore it for the next update)

Demigiant commented 4 years ago

P.S. Closing the issue but if you have other questions on this argument please continue writing them here :)