Is DOTween Path relative movement possible?
« on: April 11, 2016, 12:58:12 AM »
Hello again.  I was wondering if it were possible to have a gameobject moving on a DOTween path move relative to its own position instead of world coordinates?  If my understanding is correct, is the "Relative" option in the Path Editor only applicable to editing the tween and does not apply to when the tween is actually used?

When I start a tween, the object always pops/teleports to waypoint 1's world coordinates when it begins.   Additionally, if a tween is in progress and something happens like a physics force to an object, it will pop back to the waypoint's world position which does not look good.  I've tried "Local Movement" but it does not seem to fix this.  For instance if I make waypoint 1 be (0, 40, 0), can I make the object just move to y 40 from wherever the gameobject is (treating the gameobject as (0, 0, 0), rather than teleport to (0, 40, 0) when the path is started?  If an object's position changes between one waypoint to the next, can it smooth it out and re-plot the next waypoint accordingly instead of popping?  I know I can probably just use DOMove for simple movement but Path patterns allow so much more.  I apologize if I may not understand very well how it works.

Perhaps a solution can be brute-forced by having the waypoint values offset based on the gameobject's position when the tween is started or when a waypoint is reached, but I have a feeling that there is a built-in or correct way to do this that I have not found.  Please advise.  Again, thank you very much for your tool.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Is DOTween Path relative movement possible?
« Reply #1 on: April 11, 2016, 04:23:31 PM »
Ahoy!

Once you set the path, it's fixed, and indeed the "relative" option only involves the drawing part. But! There's a but! If you call myDOTweenAnimation.DORestart(true), your tween will be restarted by considering the current position of your object as the starting point, and readapting the whole path to it :)

Cheers,
Daniele

Re: Is DOTween Path relative movement possible?
« Reply #2 on: April 24, 2016, 11:33:07 AM »
Thank you for the advice and idea.  So does this mean I can make a path tween that starts slow or with little movement and when it gets to waypoint 1 I can immediately call a DORestart and have its path re-adapt to its current position?  My goal is to have enemies spawn in at different places, then have them use the same path relative to their position.  Would it work if I did that right when they spawned in?

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Is DOTween Path relative movement possible?
« Reply #3 on: April 24, 2016, 12:52:19 PM »
Yes, that would work indeed. Also consider that you can change your path tween's timeScale at any moment, using the tween reference and the timeScale property (which affects the timeScale of that specific tween only).

Re: Is DOTween Path relative movement possible?
« Reply #4 on: April 24, 2016, 05:01:17 PM »
I'm having trouble getting DORestart to work... if I set it up like this:
Code: [Select]
myPathTween.DORestart(true);
with myPathTween being the name of the path tween I'm using, I get an error "does not contain a member "DORestart'..."

I noticed your example mentions myDOTweenAnimation... I don't have a DOTween animation(?) in my script or on my object.. only the path; are they two different things?  How can I implement the restart?  If I just do a restart, it still pops back to the waypoint position.  Currently the part of my code I'm trying to do the restart on looks like this, and does not work.  Please advise, thank you!!

Code: [Select]
void Start ()
{
tempPosition = gameObject.transform.position;
spawnedTime = Time.time;
myPathTween = this.GetComponent<DOTweenPath>().GetTween();
myPathTween.OnWaypointChange(WPCallback);
myPathTween.Play();
}

void Update ()
{
if (restartAfterSpawning == true && Time.time >= (spawnedTime + restartDelay)  &&  restartGate == true)
{
myPathTween.Pause();
restartGate = false;
gameObject.transform.position = tempPosition;
myPathTween.Restart();
myPathTween.timeScale = 1f;

}
}

« Last Edit: April 24, 2016, 05:02:57 PM by princemoonrise »

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Is DOTween Path relative movement possible?
« Reply #5 on: April 24, 2016, 06:49:18 PM »
Hi,

DORestart(fromHere) is a special method that is not part of the core tween engine, but only of DOTweenAnimation and DOTweenPath objects.
So you should store a reference to your DOTweenPath in order to call that, not to the tween it generates.

Re: Is DOTween Path relative movement possible?
« Reply #6 on: April 24, 2016, 09:46:55 PM »
Okay, thanks for the tip, I think I got it to work; I used DOTweenPath instead of Tween when declaring, then the DORestart worked. Luckily it still let me keep my waypoint references with the Tween variable.  At first it didn't work but it was because I didn't have Relative checked in the path editor - but once I did that, no more popping when starting the tween.  Many many thanks!  :)

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Is DOTween Path relative movement possible?
« Reply #7 on: April 24, 2016, 10:04:47 PM »
Yey! :)