Open xjjon opened 4 years ago
For 2-D games in a 3D world it would be nice to have a DOJumpZ:
public static Sequence DOJumpZ( this Transform target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) { if (numJumps < 1) numJumps = 1; float startPosZ = 0.0f; float offsetZ = 1f; bool offsetYSet = false; Sequence s = DOTween.Sequence(); Tween zTween = DOTween.To(() => target.position, x => target.position = x, new Vector3(0.0f, 0, jumpPower), duration / (numJumps * 2)) .SetOptions(AxisConstraint.Z, snapping) .SetEase(Ease.OutQuad) .SetRelative() .SetLoops(numJumps * 2, LoopType.Yoyo) .OnStart(() => startPosZ = target.position.z); s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0.0f, 0.0f), duration) .SetOptions(AxisConstraint.X, snapping) .SetEase(Ease.Linear)) .Join(DOTween.To(() => target.position, x => target.position = x, new Vector3(0.0f, endValue.y, 0.0f), duration) .SetOptions(AxisConstraint.Y, snapping) .SetEase(Ease.Linear)).Join(zTween) .SetTarget(target) .SetEase(DOTween.defaultEaseType); zTween.OnUpdate(() => { if (!offsetYSet) { offsetYSet = true; offsetZ = s.isRelative ? endValue.z : endValue.z - startPosZ; } Vector3 position = target.position; position.z += DOVirtual.EasedValue(0.0f, offsetZ, zTween.ElapsedPercentage(true), Ease.OutQuad); target.position = position; }); return s; }
For 2-D games in a 3D world it would be nice to have a DOJumpZ: