Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HOTween: a fast and powerful Unity tween engine

Discussion in 'Assets and Asset Store' started by Demigiant, Jan 7, 2012.

  1. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Thanks! :)

    *dies*

    :D
     
  2. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    Very sorry if the question has it been asked, but is it possible to tween a public variable?. If yes, can you post an example?
     
  3. URZqqq

    URZqqq

    Joined:
    Dec 9, 2013
    Posts:
    4
    Hello,

    Sorry if this question has been asked before, but google didn't help me :eek:

    With the help of the example I found here :
    http://www.holoville.com/hotween/examples.html
    I successfully used HOTween to make a character follow a path.

    As I wrote code, I realized I needed a newer version of HOTween to take advantage of this function:
    Code (csharp):
    1.  
    2. OrientToPath(0.02f, Axis.X | Axis.Z)
    3.  
    (the HOTWeen version available with the example seems older than the one you can find on the asset store)

    Problem: With the newer version, I can't get my character to follow the path at constant speed :(

    Here is a screenshot:
    $demoPath.png

    And here is the simplified code I'm using:

    Code (csharp):
    1.  
    2. void Start()
    3. {
    4.     Vector3[] playerPath = GetPathFromAnotherObject();
    5.    
    6.     HOTween.To(transform, 2,
    7.                        new TweenParms().
    8.                            Prop("position", new PlugVector3Path(playerPath).
    9.                            OrientToPath(0.02f, Axis.X | Axis.Z) ).
    10.                            SpeedBased().
    11.                            Ease(EaseType.Linear));
    12.    
    13.     HOTween.showPathGizmos = true;
    14. }
    15.  
    Can someone help me ? :)

    Thanks in advance
     
    Last edited: Dec 18, 2013
  4. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Hi Izitmee

    I'm having an urgent issue. I released a game full of tweens for android and somehow Samsung phones are not running the tweens correctly, i can't really say if it affects all samsung phones, but the few we tested the behavior is as follows:

    1. Any kind of hotween configuration and tween configuration runs without problems BUT update time scale is really really low, a tween of 1 second takes about 10 minutes to run to completion. Time.timeScale is okay. I've debugged it thoroughly and nothing seems wrong on my side, and in fact it runs well in all our other test devices including iOS, so basically this only happens on Samsung phones.

    2. If i use indepent update timescale the tween doesn't even start

    3. Updatetype.fixedupdate runs each update at aprox. 30 sec each

    I tried running as a normal tween inside a function and even inside a coroutine. It doesn't matter. I have the latest version of hotween.

    EDIT: i tried the demoscene and the bahavior is the same, everything is scaled down, meaning, the float tween increases rapidly but at very small numbers, the string tween types at a very slow pace (about a minute a letter), you can hardly notice any movement of the cubes.
     
    Last edited: Dec 20, 2013
  5. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Sorry for the late answers guys, but I'm still pretty sick :p

    @ZJP: sure, that's what HOTween is all about :) For example, let's say you have a public float "someFloat", which is a member of a class instance you refer to as "someClass", you can do it in two ways...
    Tween from inside the class itself:
    Code (csharp):
    1.  
    2. HOTween.To(this, 1, "someFloat", 100);
    3.  
    Tween from a class which holds a reference to the someClass instance:
    Code (csharp):
    1.  
    2. HOTween.To(someClass, 1, "someFloat", 100);
    3.  
    Obviously, you can use the TweenParms for more advanced usage.

    @URZqqq: the examples have very outdated HOTween versions, and a newer one should always be replaced there. The fact that constant speed doesn't happen is very weird: I'll investigate :O

    @kebrus: HOTween's update uses regular Unity Update and regular Unity Time.deltaTime to measure time, so the only possible reason is that on that Samsung Time.deltaTime returns wrong results. Can you test that?
    EDIT: I'm publishing a game (Goscurry) on mobile right now, which has tons of tweens, but on all Samsung devices it was tested on I don't have this issue. What models did you use?
     
  6. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    kebrus, that's quite scary! Have you hooked up the profiler? Also you don't happen to have vendor-specific logic elsewhere in your code, do you? Do you use while loops anywhere, like for downloading assets or something?
     
  7. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    I just tried debuging delta time, on pc i get around 0.001 or 0.002 seconds, on my samsung test device i get 1E -05.

    how could this be?

    EDIT: @ God at play: I'm not using any specific code, but that doesn't even matter since i get the exact same result using hotween demoscene.
     
  8. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Izitmee, is there some way I can pause a tween, start another tween on that same property, and then resume the previous tween? Right now when I'm resuming the previous tween, it's not resuming, since I presume the newer tween has killed the previous one.

    Hope you get well soon, too!
     
    Last edited: Dec 20, 2013
  9. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @kebrus: that's pretty crazy. It would mean that Unity's time.deltaTime is completely f****d up on those devices. You're absolutely sure that timeScale is ok, right? If so, the only solution is to open a support ticket with Unity, and while you wait for it to be fixed, you could investigate more and determine what is the timeScale variation, so you can increase it on those phones (like to 100) to simulate normal behaviours.

    @God at play: as long as you pause the tween BEFORE applying the new one (no need to wait one frame, just one row of code under the other), and then resume the first one after the second one is complete, everything works (I just made a quick test to verify that). Maybe you're starting the other tween before pausing the first one?
    EDIT: thanks for the get well wishes :)
     
  10. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    That's good to know, I must have some detail wrong then. Here's my code:
    Code (csharp):
    1.  
    2.     public void ControlTweens (string id, TweenControlMethod method)
    3.     {
    4.         if (method == TweenControlMethod.PLAY)
    5.         {
    6.             HOTween.Play(id);
    7.         }
    8.        
    9.         if (method == TweenControlMethod.PAUSE || method == TweenControlMethod.RESUME)
    10.         {
    11.             List<IHOTweenComponent> tweens = HOTween.GetTweensById(id, false);
    12.             foreach (IHOTweenComponent t in tweens)
    13.             {
    14.                 if (method == TweenControlMethod.PAUSE)
    15.                 {
    16.                     t.Pause();
    17.                     // get position to apply it back on resume (needed since resume isn't working on its own)
    18.                     tweenPos = t.position;
    19.                 }
    20.                 else if (method == TweenControlMethod.RESUME)
    21.                 {
    22.                     // goto position saved during pause and play
    23.                     t.GoToAndPlay(tweenPos);
    24.                    
    25.                     Debug.Log(t.ToString() + " resumed at " + tweenPos);
    26.                 }
    27.             }
    28.         }
    29.        
    30.         if (method == TweenControlMethod.COMPLETE)
    31.         {
    32.             HOTween.Complete(id);
    33.         }
    34.     }
    35.    
    36.     public void FlashLightning ()
    37.     {
    38.         ControlTweens("SceneLighting", TweenControlMethod.PAUSE);
    39.        
    40.         TweenParms tweenParams = new TweenParms().
    41.             Id("Lightning").Prop("ambientColorCurrent", lightningColor).
    42.             Ease(EaseType.EaseOutCubic).Loops(2, LoopType.YoyoInverse).OnUpdate(UpdateAmbientColorTween);
    43.         HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
    44.        
    45.         tweenParams = new TweenParms().
    46.             Id("Lightning").Prop("fogColorCurrent", lightningColor).
    47.             Ease(EaseType.EaseOutCubic).Loops(2, LoopType.YoyoInverse).OnUpdate(UpdateFogColorTween);
    48.         HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
    49.        
    50.         tweenParams = new TweenParms().
    51.             Id("Lightning").Prop("diffuseColorCurrent", lightningColor).
    52.             Ease(EaseType.EaseOutCubic).Loops(2, LoopType.YoyoInverse).OnUpdate(UpdateDiffuseColorTween);
    53.         HOTween.To(sceneLightingStates[currentStateID], 0.2f, tweenParams);
    54.        
    55.         Invoke("ResumeLighting", 0.5f);
    56.     }
    57.    
    58.     public void ResumeLighting ()
    59.     {
    60.         ControlTweens("SceneLighting", TweenControlMethod.RESUME);
    61.     }
    62.  
    I have 5 or 6 tweens and the other ones resume just fine, but these 3 here - the ones that have this new tween used on them - don't.
     
    Last edited: Dec 20, 2013
  11. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    I found the culprit

    After further testing we them found out the problem was only happening on some samsungs and with our player settings and eventually we found out the problem was the multithreaded rendering, for some reason it breaks Unity time on some devices, having it off solved the problem instantly.

    I understand the concept of multi threads but i'm not really sure why was this problem happening, if anyone knows i would love to know. Still, thx Izitmee for the help, the unity time hint did help us find the problem.
     
  12. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @kebrus: glad you found the culprit. From what I know, the new mobile multithreading is sadly still rather buggy. But sooner or later it will hopefully work.

    @God at play: one problem might be that you're using OnComplete on the first tween. So the two others will be completed in the same frame, but are not yet completed when the first one is. A Sequence would be better there, so you can call the Sequence OnComplete and make sure every tween has finished playing before restarting. Still, even if the previous tweens are not yet stopped, that shouldn't be an issue, so I'm thinking something else is at work there? Also, as a tip, instead of using a foreach each time you want to stop those tween, you could give them a specific id (or intId, which is even faster), and just call
    Code (csharp):
    1.  
    2. HOTween.Pause(myId);
    3.  
    which will pause all tweens with the given id (and you can do the same with Play/Complete/etc).
     
  13. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks for the suggestion! I've tried something a little safer (see code) and have also implemented your suggestion - where possible at least. Still no resuming, and my output always shows the same position, confirming that the tween is indeed not resuming, although the 3 tweens are still accessed when I get them by id.

    I've updated my code in the original post so as not to clog up the thread here.
     
    Last edited: Dec 20, 2013
  14. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Can you manage to reproduce the issue in a small project so you can send it to me? So I can check it out and see if something's wrong, or if there's indeed a bug somewhere.

    By the way, I'm assuming you're using HOTween.Init to activate the OverwriteManager. Did you try to disable it and see what happens?
     
  15. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Thanks for being willing to take a look! I sent it your way. I did try to disable and that didn't make a difference.

    EDIT: Arg, PM interface is annoying, resent to you!
     
    Last edited: Dec 21, 2013
  16. CrazyLikeAFox

    CrazyLikeAFox

    Joined:
    Mar 8, 2011
    Posts:
    71
    Hi!

    I'm having some trouble with PlugVector3Path. It works with C# but not with Boo, and I can't figure out why.
    The following simple test:
    Code (csharp):
    1.  
    2. path as (Vector3) = array(Vector3, 1)
    3. PlugVector3Path(path)
    4.  
    Gives the error: "'Holoville.HOTween.Plugins.PlugVector3Path' does not have a visible constructor that matches the argument list '((UnityEngine.Vector3))'"

    It works however with the C#:
    Code (csharp):
    1.  
    2. Vector3[] path = new Vector3[1] ;
    3. new PlugVector3Path(path);
    4.  
    The C# and Boo snippets should be equivalent, both passing an array of Vector3, so I'm kind of stumped. Using C# is no big hurdle but since the rest of my stuff is written in Boo I would prefer to keep it uniform.
     
  17. NeophyteGamer

    NeophyteGamer

    Joined:
    Aug 26, 2013
    Posts:
    38
    Thank you very much for writing this but I have an issue attempting to use it

    sequence1 = new Sequence(new SequenceParms());
    sequence1.Append(HOTween.To(gameObject.transform, 3, "position", Vector3(0,1,0)));
    sequence1.Append(HOTween.To(gameObject.transform, 5, "position", transform.position));
    sequence1.Append(HOTween.To(gameObject.transform, 3, "position", Vector3(0,0,0)));
    sequence1.Play();

    I wanted a pause in between the tweens in the sequence but it seems to skip the second tween altogether.
     
  18. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @CrazyLikeAFox: ouch, the only possible reason for that is that Boo doesn't support optional parameters as C# does. Can you confirm that? In the meantime, fill that optional parameter by adding the pathtype (PathType.Linear or PathType.Curved) and it will work.

    @NeophyteGamer: To add a pause to a Sequence, don't add a fake tween, but instead use AppendInterval:
    Code (csharp):
    1.  
    2. sequence1.AppendInterval(5);
    3.  
     
  19. Artem86

    Artem86

    Joined:
    Sep 20, 2013
    Posts:
    3
    Hi, thanks for HOTween. He's the best!
    Please tell me how to do the following:
    Code (csharp):
    1.     private IEnumerator Start()
    2.     {
    3.         var seq = new Sequence();
    4.         seq.Play();
    5.         seq.AppendCallback(() => Debug.Log("Start"));
    6.         seq.AppendInterval(3);
    7.         yield return StartCoroutine(seq.WaitForCompletion());
    8.         seq.AppendCallback(() => Debug.Log("After Wait")); //not play becouse isComplite == true
    9.     }
    How to continue playing in this case?
     
  20. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Not sure what you want to do, since you're creating an empty sequence. If you want to use HOTween just as a timer, that's not its purpose, and since you're already inside a Couroutine you could directly use Unity's WaitForSeconds instead.
     
  21. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    NEW HOTWEEN UPDATE V1.1.882

    - Added PlugColor32 (automatically used in case of Color32 values)
    - Added optional forcePlay parameter to all Reverse methods
    - OverwriteManager now ignores paused tweens
    - Fixed bug where GoToAndPlay didn't play if the tween was at the same position where it was sent via the goto

    As usual, get it from the website, while I update the Asset Store package.
     
  22. NeophyteGamer

    NeophyteGamer

    Joined:
    Aug 26, 2013
    Posts:
    38
  23. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    I know that people are using HOTween on Win 8 phone succesfully, so maybe there's other parts of your code causing the issue: I suppose HOTween is not the only thing that changes compared to your other games? :p
     
  24. NeophyteGamer

    NeophyteGamer

    Joined:
    Aug 26, 2013
    Posts:
    38
    Alright you win, although it was a fresh project with only hotween in it, it seems the culprit comes from having too many developer apps on my phone. It can only handle two at a time.

    Anyway great work on this thing, going to make my life easier.
     
  25. Artem86

    Artem86

    Joined:
    Sep 20, 2013
    Posts:
    3
    No, I do not use sequence as timer, the above code only to simplify the example. I use HOTween.To within the sequence. In my case WaitForCompletion() waits executed HOTween.To
    This is another example:
    Code (csharp):
    1.             var target = PhotonView.Find(targetViewID).GetComponent<BaseCreature>();
    2.             var sequence = new Sequence();
    3.             sequence.Play();
    4.             sequence.AppendCallback(Owner.DoCast); //play cast animation
    5.             sequence.AppendInterval(Owner.CastDelay); //delay for Instatiate magicFX object
    6.             sequence.AppendCallback(() => magicFX = (GameObject) Instantiate(FX, Owner.MagicPoint.position, Quaternion.identity)); //Create magicFX object
    7.             yield return StartCoroutine(sequence.WaitForCompletion()); //wait until the object will be created
    8.             sequence.Append(HOTween.To(magicFX.transform, 4,
    9.                 new TweenParms().Prop("position", target.MagicPoint.position) //move magicFX. If don't use WaitForCompletion in this line the object magicFX == null
    10.                                 .SpeedBased()
    magicFX object can not be created without sequence.
    My question is how to continue to play the sequence again after WaitForCompletion()?
     
  26. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Wohooo!!! I win! I win! :D That said, it's crazy that you can't have more than two dev apps on your phone. Is it a limitation of Win8 phone, or of your specific type of phone?

    @Artem86: Oh I see. In that case, the reason is that you can't create a sequence, play it, and then add more stuff to it. Once you play the Sequence, its contents are locked, and you have to create a new one (or a new Tweener) to move things more.
    EDIT: in your case, you could create the first Sequence, wait for its completion as you're doing, and then just create a new tween for magicFX.
     
  27. Artem86

    Artem86

    Joined:
    Sep 20, 2013
    Posts:
    3
    ok, thank you Izitmee
     
  28. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    I dont understand the API very well. Can anyone tell me why sometimes this rotates clockwise, and sometimes counterclockwise? It seems pretty random which direction it chooses. I suspect it's tweening localRotation, and something in the parent hierarchy is rotated. Maybe.

    HOTween.To(lastMoveMarker.transform, 5, new TweenParms().Prop("rotation", new Vector3(0, 45, 0)));
     
  29. tequibo

    tequibo

    Joined:
    Jun 4, 2013
    Posts:
    19
    Hey Izitmee,
    Already wrote about problem this problem.

    I get this error on every frame and ALL TWEENS stop working. If I press "kill all tweens" in the inspector it's all fine again.

    I finally get around to try and fix it. Added stored reference to tweeners and added Kill() to where enemy projectiles gets destroyed.
    Not sure if it fixes it yet, as this bug is not easy to reproduce as it happens occasionally. Which is super weird most of the times it's fine if prefab with tween gets destroyed, but rarely it breaks everything! Or maybe it's because object I call HOTween.From gets destroyed could be the reason? Anyway it happens when enemy gets killed by explosion which destroys enemy projectiles as well, which have tween to scale them up when they shot by enemy.

    Still, maybe you could add some sort of check for null reference, as it can be hard to clean tweens everywhere where object can be destroyed in some cases. Here is a error from latest version, v1.1.882, so line numbers should be ok, in case you will decide to do this:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. Holoville.HOTween.Tweener.Startup (Boolean p_force) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:997)
    4. Holoville.HOTween.Tweener.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:986)
    5. Holoville.HOTween.Tweener.Rewind (Boolean p_play, Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:926)
    6. Holoville.HOTween.Tweener.Rewind (Boolean p_skipDelay) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:278)
    7. Holoville.HOTween.Tweener.Rewind () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Tweener.cs:267)
    8. Holoville.HOTween.Sequence.TweenStartupIteration () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:876)
    9. Holoville.HOTween.Sequence.Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:903)
    10. Holoville.HOTween.Sequence.Update (Single p_shortElapsed, Boolean p_forceUpdate, Boolean p_isStartupIteration, Boolean p_ignoreCallbacks) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Sequence.cs:645)
    11. Holoville.HOTween.Core.ABSTweenComponent.Update (Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/Core/ABSTweenComponent.cs:954)
    12. Holoville.HOTween.HOTween.DoUpdate (UpdateType p_updateType, Single p_elapsed) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:2073)
    13. Holoville.HOTween.HOTween.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__HOTween.Assembly/HOTweenV1/HOTween.cs:666)
     
  30. CrazyLikeAFox

    CrazyLikeAFox

    Joined:
    Mar 8, 2011
    Posts:
    71
    Optional parameters are indeed not implemented in Boo. Works perfect when supplying the PathType. Obvious error in retrospect, thanks!
     
  31. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @mindlube: the rotation will happen in the shortest "direction" needed to reach 0,45,0. If you want to rotate something BY 45, add a TRUE for the "relative" option, like this:
    Code (csharp):
    1.  
    2. HOTween.To(lastMoveMarker.transform, 5, new TweenParms().Prop("rotation", new Vector3(0, 45, 0), true));
    3.  
    @tequibo: the reason is certainly because the target becomes null while still tweening. I recommend implementing some kind of destroy behaviour on each element, so you can clean event listeners, tweens, and other stuff. I implemented some checks to see if a target becomes null, but they don't always work because a) sometimes Unity is strange, and something might be null but not truly null, b) those checks are not called every frame, because otherwise they would slow the tween engine down.
     
  32. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi lzitmee, I want to make a persistent sequence in my scene, so I can append tweener and play them 1 by 1 anytime.
    What I do is set sequence.autoKillOnComplete=false, and foreach tweener set tweenParms.AutoKill(true).
    But it appearance that the tweener can't remove itself after complete, and new tweener can't be play if it was add after previous tweener finished.
    What's the proper way to do this? Thank you :)

    Code (csharp):
    1. void Start ()
    2.         {
    3.                 seq = new Sequence (new SequenceParms ());
    4.                 seq.autoKillOnComplete = false;
    5.                 StartCoroutine (Play ());
    6.         }
    7.  
    8.         IEnumerator Play ()
    9.         {
    10.                 seq.Play ();
    11.                 yield return new WaitForSeconds (1f);
    12.                 Rotate (2f); // this will run
    13.                 yield return new WaitForSeconds (5f); // wait until the first one complete
    14.                 Rotate (2f); // this will not
    15.         }
    16.    
    17.         public void Rotate (float duration)
    18.         {              
    19.                 TweenParms _parm = new TweenParms ();      
    20.                 _parm.Prop ("rotation", new Vector3 (0f, -900f, 0f), true).Ease (EaseType.EaseOutSine).AutoKill (true);
    21.                 seq.Append (HOTween.To (this.transform, duration, _parm)); 
    22.                 seq.Play ();
    23.         }
     
    Last edited: Dec 28, 2013
  33. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi zhuchun. Sorry but that can't be done. Once you create a Sequence and start playing it, it becomes locked, and you have to create a new one (or a new Tweener) if you want to tween more.
     
  34. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Oh I see, thanks anyway :)
     
  35. CrazyLikeAFox

    CrazyLikeAFox

    Joined:
    Mar 8, 2011
    Posts:
    71
    Hello again.

    So, I've got my Vector3Path all working, however "OrientToPath" is giving me a headache. No matter what percentage I set it to at some point my transform it will suddenly flip and face backwards. My path is not that complex with mostly straight lines and some horizontal turns. I'm probably missing something obvious again.
     
  36. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Can you replicate it in a simple barebone project and send it to me? So I can check it out? :)
    EDIT: even if you do it in Boo it's ok
     
  37. CrazyLikeAFox

    CrazyLikeAFox

    Joined:
    Mar 8, 2011
    Posts:
    71
    OK. So it works perfectly when I do it in a clean project with basicaly the same kind of path, which means the problem is most probably with my code.
     
  38. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Uhhh that's a mystery then. Maybe you start another tween at some point which overwrites the previous one? Or you modify your transform manually for some reason?
     
  39. CrazyLikeAFox

    CrazyLikeAFox

    Joined:
    Mar 8, 2011
    Posts:
    71
    Indeed. No nothing like that. My mostly straight path has not issues, but one which curves around (but does not close) has this wonky behaviour. As you can see from the screens, it starts out flipped, then corrects itself, (and afterwards flips back again).
     

    Attached Files:

  40. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Mhmm that seems one of the errors I had at the beginning of HOTween, and that caused me tons of headaches until I fixed it for good. I wouldn't know what to suggest unless you can replicate it though :(
     
  41. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
  42. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    To change a position with HOTween, you can simply do like this:
    Code (csharp):
    1.  
    2. HOTween.To(myTransform, myTime, "position", new Vector3(2,2,2));
    3.  
    To recognize a tap instead it depends on the way you scripted it all, but usually a simple raycast should be enough (I'm sure you can find tons of ready-made code here on the forums).
     
  43. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    I get this error even though I have HOTween installed:
    error CS0103: The name `HOTween' does not exist in the current context

    The only call I have to HOTween is:
    HOTween.To(pickedShape.transform.position, 1, "position", new Vector3(0,5,0));


    Thanks
     
  44. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    If you want to use HOTween, you have to import the namespace in each class that uses it (see the "get ready to code" chapter in the intro).
     
  45. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Dude, you are super awesome!

    As you can grasp, I am a beginner but I am super excited about HOTween and can't wait to learn more.


    Thanks!
     
  46. Flashist

    Flashist

    Joined:
    Jun 25, 2013
    Posts:
    11
    Hi.
    First of all I want to say thank you for your great job on developing HOTween.

    And here is my question: I want to make some kind of static function, which will destroy object, which was tweened by HOTween.Tweener. It could be useful if you use alpha-off visual effect very often.

    For example:
    1) I have some toolkit 2d sprite and want to "alpha-off" it.

    2) For that I will write next code:
    Code (csharp):
    1. TweenParms tweenParams = new TweenParms();
    2. tweenParams.Prop(TweenTools.colorParamName, transpColor);
    3. tweenParams.Ease(EaseType.EaseOutQuad);
    4. tweenParams.OnComplete(TweenTools.DestroyTargetOnTweenComplete);
    5. HOTween.To(view, 0.4f, tweenParams);
    Where "TweenTools" is my custom created class and DestroyTargetOnTweenComplete is function about I have told. Here code of that function:
    Code (csharp):
    1. static public void DestroyTargetOnTweenComplete(TweenEvent tweenEvent)
    2. {
    3.     Tweener tweener = (Tweener) tweenEvent.tween;
    4.     if(tweener == null)
    5.     {
    6.         return;
    7.     }
    8.  
    9.     Object targetObj = (tweener.target as Object); 
    10.     if (targetObj == null)
    11.     {
    12.         return;
    13.     }
    14.    
    15.     // Here will be code of destruction tweener.target
    16. }
    3) The bad thing is tweener.target variabale is null. If I am understending source code correctly, it happens because variable target become null just after calling Complete function.

    Am I right? And please, could you advice me some way to make independed static function for reason that I have wrote.

    Regards,
    Mark.

    P.S.: sorry for my English.
     
  47. Flashist

    Flashist

    Joined:
    Jun 25, 2013
    Posts:
    11
    I have just found that I can use OnStepComplete callback for my reasons (in that way variable target isn't null). But, anyway, I think that it will be useful if variable target aren't equal to null before OnComplete callback will be called.

    Regards,
    Mark.
     
    Last edited: Jan 3, 2014
  48. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    @gegagome: thanks for your enthusiasm, and have fun with the beginning :)

    @Flashist: you're totally right. I will check now and see how that can be changed.
     
  49. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Allright, after some fun with the Visual Editor I wanted to actually script some tweens, too and also combine my created Tweens in the Visual Editor with my scripts.

    What I want to do:

    - when my Character hits an enemy he looses health (duh!)

    My code looks like this:

    Code (csharp):
    1. void OnTriggerEnter(Collider other)
    2.     {
    3.         if(other.tag == "EnemyTrigger")
    4.         {
    5.             if(playerHealth != 0)
    6.             {
    7.                 playerHealth -= 1;
    8.  
    9.                 HOTween.Play("HEART01_DOWN");
    10.             }
    11.             else
    12.             {
    13.                 playerHealth = 0;
    14.             }
    15.         }
    16.  
    17.     }
    18.  
    19.  
    The string "HEART01_DOWN" is the ID of the Tween which is created at the HOTweenComponent of an UISprite-Object in my nGUI-UI.

    When the game runs, the Tween is played. It's tweening/moving the localPosition of the Object. Everythings works fine.

    But wait, there's more!
    This tween only moves the heart down. I need not only the localPosition to change but also the Alpha-Value of the sprite, the localRotation and so on.

    I looked up your Sequences and I think that is what I'm after, but I don't know how to create my special "tween-chain".
     
  50. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    If the target is the same, you could use the same Tweener to tween multiple properties. That's not your case though, since you have different targets, so Sequences is the right way to go.

    Here is how you would do it, where "myTween0/1/2" are regular tweens that you would create to animate those properties:
    Code (csharp):
    1.  
    2. Sequence mySeq = new Sequence();
    3. mySeq.Insert(0, myTween0);
    4. mySeq.Insert(0, myTween1);
    5. mySeq.Insert(0, myTween2);
    6. mySeq.Play(); // contrary to Tweeners, Sequences are created in a paused state
    7.  
    I'm using Insert to make all those tweens play together. If you wanted them to play in a row, you would use mySeq.Append instead.