Jump to content
Search Community

MotionPath fromCurrent not working as expected

Les Prétentieux test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi @Les Prétentieux and welcome to the GSAP Forums!

 

As far as I can tell, the MotionPath Plugin is doing exactly what's supposed to. Is not including the 0, 0 coordinates in the array, but your element is actually at x: 0, y: 0 when the animation is created, so obviously the plugin has to move the element from that position to the first point in the array being passed so it becomes part of the path.

 

You could try something like this:

gsap.to(".box", {
  x: 100,
  y: 100,
  duration: 1,
  onComplete: () => {
    const tween = gsap.to(".box", {
      motionPath: {
        path: [
          { x: 100, y: 100 },
          { x: 200, y: 100 },
          { x: 200, y: 200 },
          { x: 100, y: 200 },
          { x: 100, y: 100 }
        ],
        curviness: 0,
      },
      duration: 6,
      ease: "power3.inOut"
    });
    MotionPathHelper.create(tween);
  }
});

Or perhaps something like this:

gsap.set(".box", {
  x: 100,
  y: 100,
});

var tween = gsap.to(".box", {
  motionPath: {
    path: [
      { x: 100, y: 100 },
      { x: 200, y: 100 },
      { x: 200, y: 200 },
      { x: 100, y: 200 },
      { x: 100, y: 100 }
    ],
    curviness: 0,
    fromCurrent: false
  },
  duration: 6,
  ease: "power3.inOut"
});

MotionPathHelper.create(tween);

Finally thanks for being a GSAP Club member and supporting GSAP! 💚

 

Hopefully this helps.

Happy Tweening!

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