Jump to content
Search Community

Split/duplicate animation to a new path once coordinates are reached

SammyC123 test
Moderator Tag

Go to solution Solved by GreenSock,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

When the ball reaches an intersection of another line, I would like that ball to split/duplicate itself and begin traversing that second path while the first ball continues on its own course.

 

I am trying to determine a method programmatically to make this happen, so that the solution is extensible to any number of additional lines. So far, I have come up short.

 

Is it possible to use TweenMax to detect when a set of coordinates is reached on a path? (e.g. where the second path begins at M90.7, 86.7) Or is this going to rely solely on timing, in which case easing is pretty much thrown out the window because everything must be linear?

 

Thanks in advance for any assistance rendered.

See the Pen LGOyJm by anon (@anon) on CodePen

Link to comment
Share on other sites

  • Solution

It absolutely depends on timing of course, but a few ideas come to mind that would work fine with an ease:

 

1) Manual hack: use a scrubber and visually line it up

Attach a scrubber (like a jQuery UI one) to the animation of the first curve so that you can just drag through the animation and then when it's visually lined up with where you want, you just check to see the corresponding time() on the tween that you're scrubbing through. That'll tell you exactly when that 2nd one should spawn. 

 

2) Iterate 

Just set up a JS loop that does a similar thing to what I described above so that instead of manually dragging the scrubber and watching to see when it lines up, you can just have the loop keep checking the position and see at what time() it's closest to the point you're looking for. You'd obviously need to decide on a precision level (0.01 seconds? 0.001 seconds?) so that your loop isn't like 1,000,000,000 iterations. You could record an array of distances and associated times and then just sort it accordingly and get the closest one. 

 

I hope that helps nudge in you in the right direction. :)

  • Like 4
Link to comment
Share on other sites

Here's a demo I made that finds the closest point on a path. It could be adapted to what you are trying to do.

See the Pen jbVPqw by osublake (@osublake) on CodePen

 

And here's a different version where I was testing out quadtrees with hit detection, although I din't fully implement it. A quadtree splits up an area to search in, so it's a lot faster.

See the Pen 655e4756348410e6e5608d42657749ec?editors=001 by osublake (@osublake) on CodePen

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...