robs Posted July 15, 2022 Share Posted July 15, 2022 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 More sharing options...
Cassie Posted July 15, 2022 Share Posted July 15, 2022 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 More sharing options...
robs Posted July 15, 2022 Author Share Posted July 15, 2022 Thanks, Cassie! I'll have a look at the ModifiersPlugin, but I guess I'll just go with the solution of creating a new tween each time. 1 Link to comment Share on other sites More sharing options...
GreenSock Posted July 15, 2022 Share Posted July 15, 2022 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 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now