Jump to content
Search Community

MotionPathPlugin — Reset path onRepeat

robs test
Moderator Tag

Recommended Posts

Hi, 

 

I have an element (a pony) that moves along a random path, flips and returns. I would like to recalculate that path each time the pony returns. I tried to work with vars.motionPath.path, but the new path isn't applied to the tween ... (see my comments in the code)

I there another way to update the path on the fly?

 

Thanks so much, 

Robert

See the Pen eYMBLqz by rob83 (@rob83) on CodePen

Link to comment
Share on other sites

Hey there!

 

I'd probably do something like this?

 

See the Pen RwMoEbp?editors=0010 by GreenSock (@GreenSock) on CodePen



You'll have to add a bit of conditional logic to flip the pony and change direction, but creating a new tween each time rather than trying to update the original tween is probably a better (easier) route.

 

Alternatively - maybe the modifiers plugin could help? I haven't messed about with it much but modifying existing properties is what it's for!

https://greensock.com/docs/v3/GSAP/CorePlugins/ModifiersPlugin

 

 

Link to comment
Share on other sites

Cassie's approach is solid. If you really need to reuse the same tween instance(s), you could invalidate() to force them to re-parse the vars on the next render. Just beware that if the parent timeline's playhead is passed the tween's end, it'll of course call the onComplete again on the very next tick after invalidating, thus you'd need to add some logic to skip things in that scenario. Here's a fork illustrating what I mean: 

 

See the Pen QWmdLVE?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 1
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...