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 - jgodfrey

Pages: [1]
1
DOTween & DOTween Pro / Animate object with moving endpoint
« on: March 15, 2016, 11:21:14 PM »
I'm working on an endless runner type game (actually, a vertical endless climber).  In the game the player can gather coins as they climb. When a coin is "collected", I'd like to tween it from its current position to a static location on the screen (where the GUI coin counter is located). While this seemed easy on the surface, it turns out to be harder than I expected.

While I have both a start and end position for the tween in world coords (start = coins current position, end = location of GUI coin counter (top left of screen), converted to world coords).  However, since it's an endless climber, the world coordinate system is changing while the coin is tweening.  I attempted to solve the issue using the following:

Code: [Select]
public class CoinMotion : MonoBehaviour
{
    private float _completionRadius = 0.25f;
    private float _speed = 80;
    private Vector3 _targetLoc = new Vector3(0.075f, 0.85f);

    public void MoveCoin()
    {
        Tweener tweener = gameObject.transform.DOMove(Camera.main.ViewportToWorldPoint(_targetLoc), _speed).SetSpeedBased(true).OnComplete(Finish).Play();
        tweener.OnUpdate(delegate()
        {
            // keep going until we're "close enough"
            float dist = Vector3.Distance(gameObject.transform.position, Camera.main.ViewportToWorldPoint(_targetLoc));
            if (dist > _completionRadius)
            {
                tweener.ChangeEndValue(Camera.main.ViewportToWorldPoint(_targetLoc), true);
            }
        });
    }

    private void Finish()
    {
        // pulse the coin collector GUI once the coin tween finishes...
    }
}

Note the "_targetLoc" vector represents the location of the on-screen "coin collector" in Viewport coords.  While the above mostly works, it takes too long to actually reach the destination (even if sped up to crazy values).  Also, the path seems a bit wonky depending on how fast the world coords system is changing.  At times, the world coords can change very fast (for instance, if the character is currently using a jetpack, they can climb quite fast).

It seems to me that the simple solution is to tween the coin as a "UI element" - using UI coordinates, since those wouldn't change with the world coord system.  However, maybe there's a good way to do in Worldspace also?

Any thoughts appreciated.

Thanks.

2
DOTween & DOTween Pro / Trouble with AppendInterval timing
« on: February 15, 2016, 01:00:25 AM »
I'm trying to create a strobing platform using the following Sequence:

Code: [Select]
_seq = DOTween.Sequence()
            .SetAutoKill(false)
            .SetLoops(-1, LoopType.Restart)                 // loop forever
            .SetEase(Ease.InQuad)
            .Append(_ren.DOFade(1f, 0))                     // instantly fade the sprite renderer to 100% opaque
            .AppendCallback(() => _coll.enabled = true)     // enable the platform collider
            .AppendInterval(StrobeOnTime)                   // wait for the designated "platform on" time
            .Append(_ren.DOFade(0.25f, 0))                  // instantly fade the sprite renderer to 25% opaque
            .AppendCallback(() => _coll.enabled = false)    // disable the platform collider
            .AppendInterval(StrobeOffTime);                 // wait the designated "platform off" time

The idea is to have a platform that's "on" (opaque, collider enabled) for a given amount of time and then "off" (see through, collider disabled) for a given amount of time - and loop forever.

The above works as expected, except the two "intervals" don't seem right.  If I set the two values equally, the last one (StrobeOffTiime) is always shorter than the first one.  I'm not exactly sure which one is wrong, but the timing is not as expected.

Is there anything wrong with the above?

Thanks.

3
Using Unity's new UI features, it's my understanding that the proper way to move UI panels on and off of the screen in a resolution independent manner is by modifying the associated RectTransform's anchorMin and anchorMax vectors. Currently, I'm accomplishing that via a sequence of generic tweens something like this:

Code: [Select]
    DOTween.Sequence()
        .Join(DOTween.To(() => rect.anchorMin, x => rect.anchorMin = x, new Vector2(1f, 0f), 1f))
        .Join(DOTween.To(() => rect.anchorMax, x => rect.anchorMax = x, new Vector2(1f, 0f), 1f))
        .SetRelative(true)
        .Play();

The above moves the RectTransform 1 full screen to the right without knowing anything about the screen resolution - which is the whole point.

This seems like it might be a reasonable candidate for some "shortcut" methods, such as:

Code: [Select]
DoAnchorMin(...)
DoAnchorMinX(...)
DoAnchorMinY(...)

DoAnchorMax(...)
DoAnchorMaxX(...)
DoAnchorMaxY(...)

Thanks for your consideration and a GREAT product!

Jeff

4
DOTween & DOTween Pro / Moving platform - can't quite get it right
« on: February 03, 2016, 05:42:44 AM »
I'm trying to tween a series of moving platforms.  Each platform moves either up/down between 2 points or left/right between two points continuously. For sake of discussion, let's consider a horizontally moving platform. Really, I just want to move it continuously back and forth on a known line segment, easing in/out of the endpoints.  On the surface, that's easy enough. However, the complication seems to be that when the platform is instantiated, it's already (randomly) somewhere within it's motion segment. 

So, I need to create a tween that moves from the platform's initial, random position on the line to one end of the line and then back to the other end - all while easing in/out of  the line end points.

I've tried this using transform.DoPath (with a closed, 2-point path) and with a Sequence, using 2 separate transform.DoMoveX tweens. While both generally work, I can't figure out an appropriate way to deal with the random starting location of the platform.  It seems that the path always gets an extra point inserted in it (where the transform starts out) and then the easing happens around that point - which doesn't feel right.  The Sequence method also seems to suffer from similar problems with getting the easing to happen at the endpoints.

I've even tried to move the platform's transform to one end of the segment and then doing a random "goto" to advance the tween to some random position along the line prior to playing it.  However, I always seem to end up with results that are close to what I want, but not quite right.

This seems like a simple problem on the surface, but I haven't quite figured out the secret sauce.

Advice appreciated.

5
I'm attempting to move UI panels on and off of the screen (in a resolution independent way) by tweening the anchorMin and anchorMax members of the panel's RectTransform component.  Essentially, I've parked all of my panels just off the left side of the screen by setting their anchorMin and anchorMax properties to (-1, 0) and (0, 1) respectively.

When it's time to slide a panel into view, I call the below code and pass it the GameObject containing the panel.

Code: [Select]
private void ShowHudPanel(GameObject panel)
{
    RectTransform rect = panel.GetComponent<RectTransform>();

    DOTween.Sequence()
        .Join(DOTween.To(() => rect.anchorMin, x => rect.anchorMin = x, new Vector2(1f, 0f), 1f))
        .Join(DOTween.To(() => rect.anchorMax, x => rect.anchorMax = x, new Vector2(1f, 0f), 1f))
        .SetRelative(true)
        .Play();
}

The result is odd.  Essentially, it seems like the tween is only playing for a single frame.  With the one second duration above, the panel is made barely visible on the left edge before the tween (apparently) finishes.  As I decrease the duration, the above makes the panel more visible (as each frame would have to move the panel further).  If I decrease the duration to something silly (like 0.01), the entire panel is made visible - but only because it needs to move the entire distance in a single frame.

I'm using "DOTween.defaultTimeScaleIndependent = true" to make the tweens Unity time independent.  Though, I even set that to false and ensured that my Unity time.timeScale was set to 1 and I get the same results.

I've also tried the above with and without the "SetRelative" (making appropriate adjustments to the end vectors), but the results are the same.  Originally, I assumed I had somehow misdefined the tweens, but I no longer think that's the case (since short duration's prove the tween works as expected).

It just seems like I'm only getting 1 frame of animation from the above for some unknown reason.  I'm using the most recent version of DOTween (1.1.135) and Unity 5.3.1f1.

I also tried initializing DOTween with "LogBehaviour.Verbose", but that doesn't indicate any problems in the log panel.

Thanks for your input.

Jeff

6
DOTween & DOTween Pro / Sequence - basic usage verification
« on: February 01, 2016, 03:04:51 AM »
As a new User, I just wanted to verify my usage of a typical DOTween sequence.  I've have a group of UI buttons that are "stacked" directly on top of each other (so, only the top one is visible).  When the visible button is pressed, I "expand" the underlying stack by tweening each of the buttons to their final, expanded positions.  Here's my basic sequence to do that:

Code: [Select]
        // Create a tween sequence for the Option buttons stack
        _seqOptions = DOTween.Sequence()
            .SetAutoKill(false)
            .SetRelative(true)
            .Join(transInfo.DOAnchorPosY(600, ButtonExpandTime, true))
            .Join(transMusic.DOAnchorPosY(400, ButtonExpandTime, true))
            .Join(transSoundFx.DOAnchorPosY(200, ButtonExpandTime, true));

Then, based on the value of a bool, I play the above sequence either forward (to expand the stack) or backwards (to collapse the stack).  That looks like this:

Code: [Select]
        if (_optionsExpandedState)
        {
            _seqOptions.SetEase(Ease.OutBounce).PlayForward();
        }
        else
        {
            _seqOptions.SetEase(Ease.InBounce).PlayBackwards();
        }

Notice that I have to switch the Ease property based on the direction - to get the same look in both cases. 

All of the above works exactly as intended. However, I just wanted to verify that it's a reasonable solution for what I'm doing.  Thanks for any input/verification you can provide and also for what looks to be a fantastic tweening library.

Jeff

Pages: [1]