Code Monkey home page Code Monkey logo

Comments (10)

Ayfel avatar Ayfel commented on August 20, 2024 1

Just an update. I added extensions to tween in local space of the target, that way it behaves just like following a target. I got the idea from another post. Here is the position and rotation code for it

 public static TweenerCore<Vector3, Vector3, VectorOptions> DOMoveInTargetLocalSpace(this Transform transform, Transform target, Vector3 targetLocalEndPosition,float duration)
    {
        var t = DOTween.To(
            () => transform.position - target.transform.position, // Value getter
            x => transform.position = x + target.transform.position, // Value setter
            targetLocalEndPosition, 
            duration);
        t.SetTarget(transform);
        return t;
    }

    public static TweenerCore<Quaternion, Quaternion, NoOptions> DORotateQuaternionLocalSpace(
        this Transform transform, 
        Transform target,
        Quaternion endValue,
        float duration)
    {
        TweenerCore<Quaternion, Quaternion, NoOptions> t = DOTween.To<Quaternion, Quaternion, NoOptions>((ABSTweenPlugin<Quaternion, Quaternion, NoOptions>) PureQuaternionPlugin.Plug(), (DOGetter<Quaternion>) (() => Quaternion.Inverse(target.rotation)*transform.rotation), (DOSetter<Quaternion>) (x => transform.rotation = target.rotation * x), endValue, duration);
        t.SetTarget<TweenerCore<Quaternion, Quaternion, NoOptions>>((object) transform);
        return t;
    }

To follow the object exactly use Vector3.zero and Quaternion.Identity for the targetLocalEndPosition and endvalue

from dotween.

Demigiant avatar Demigiant commented on August 20, 2024

Hello,

I thought about it, but the problem with a "follow tween" would be that it wouldn't be able to be rewinded or manipulated as the other tweens (because in order to allow it to readapt correctly to its follow target's position every frame, it would need to change its start value too). I'm thinking that maybe I could add an extra "DOTweenFollow" component just for that. What you think of it?

from dotween.

vabric avatar vabric commented on August 20, 2024

Hi,

I was thinking of something much more simpler (though a "follow tween" would be great as well). The idea is just to get the position of the GameObject as the destination when the tween start.
For example, if I want some text to move from the center of the screen to an element of my HUD, I'd like to set the element as the destination instead of entering its coordinates. This way, if I reorganize my UI layout later, I don't have to modify my tweens.
I'd be glad to help add this feature if it's ok with you.

Thanks

from dotween.

Demigiant avatar Demigiant commented on August 20, 2024

Hello,

Ah! That would be indeed much simpler! I'm going to see if I can add it later today then :) In the meantime, if you don't have access to DOTween Pro's private download area, follow these instructions, so I can send you a link as soon as it's done.

Cheers

from dotween.

Demigiant avatar Demigiant commented on August 20, 2024

Voilà :)

There is now a switch button next to the Vector3 field of Move tweens, which can be used to tell DOTweenAnimation to use a target instead of a Vector3 value

from dotween.

vabric avatar vabric commented on August 20, 2024

Awesome! Thanks for the quick update :).

from dotween.

Jayatubi avatar Jayatubi commented on August 20, 2024

Would the tween auto update the destination position if the gameobject moves away before the tween finishes?

from dotween.

 avatar commented on August 20, 2024

does the tween update its destination when the transform moves while the tween is happening ?

from dotween.

Demigiant avatar Demigiant commented on August 20, 2024

No, the position is evaluated only when the tween starts.

from dotween.

Ayfel avatar Ayfel commented on August 20, 2024

Vote for the DOTweenFollow idea, I would definitely use that

from dotween.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.