Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - ricke

Pages: [1]
1
DOTween & DOTween Pro / Transform.DOPath and Incremental Loop
« on: July 29, 2016, 06:41:35 PM »
Hi there.  I just got DOTween yesterday and think it's fantastic!  I've been playing with it for use in a 2D game space shooter that I'm making and love the features.

As I'm noobish to DOTween, I'm running into an issue using DOPath on a transform and trying to loop incrementally, perhaps I'm not understanding how/if it should work. :D

In this particular scenario, I have an enemy ship that starts in a random location on the screen.  I want it to zig zag (think in a 'Z' shape) on the screen relative to it's position until it moves past the bottom of the screen, at which point the enemy will destroy itself and respawn at the top.

To that end, I'm using a simple path that should give me the top and diagonal part of the 'Z', then I want that path to repeat infinitely from it's new position at the end of path.  I'm doing this in a little static method on a static class, with the plan to have multiple tween patterns that I can use at will on enemies in the game.  Here's what I've got:

Code: [Select]
public static class EnemyMoves
{
    public static Tween ZigZag(Transform transform, float duration)
    {
        Vector3[] path = new[]
        {
            new Vector3(200, 0),
            new Vector3(-100, -200)

        };

        return transform.DOPath(path, duration, PathType.Linear, PathMode.TopDown2D).SetRelative().SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental);
    }
}

When I use this on my enemy game object, it will complete the path one time relative to the enemy's starting position, then it quits (on the Scene view, I see the Path gizmo disappear, so I assume the tween completed and was killed?)  If I use either Restart or Yoyo for the loop type, the enemy tweens along the path indefinitely like it should (either starting over or moving back along the path respectively).

Any ideas what I'm doing wrong?  Any thoughts would be most appreciated.  ;D  Thanks.

Pages: [1]