Jump to content
Search Community

Bezier Direction always the same?

shaderbytes test
Moderator Tag

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

So I created a plane following a quad bezier , i thought switching point 1 and point 3 would invert the bezier direction but it does not.

 <script>
        
        $("#remote-vacationicon").on("click",MovePlaneLeft);
        $("#remote-houseicon").on("click",MovePlaneRight);
        function MovePlaneLeft() {
            MovePlane("left");
        }
        function MovePlaneRight() {
            MovePlane("right");
        }
        function MovePlane(direction) {
            console.log("MovePlane " + direction);
            var house = $("#remote-houseicon");
            var vacation = $("#remote-vacationicon");
            var hp = house.position();
            var vp = vacation.position();            
            var midpointx = Math.abs(hp.left - vp.left);
            var midpointy = Math.abs(hp.top - vp.left);
            if ("right") {
                TweenMax.to(document.getElementById("remote-plane"), 5, { bezier: { type: "quadratic", curviness: 1, values: [{ x: vp.left, y: vp.top, scaleX: 0, scaleY: 0 }, { x: midpointx, y: midpointy, scaleX: 1, scaleY: 1 }, { x: hp.left, y: hp.top, scaleX: 0, scaleY: 0 }], autoRotate: true }, ease: Power1.easeInOut });
            }
            if ("left") {
                TweenMax.to(document.getElementById("remote-plane"), 5, { bezier: { type: "quadratic", curviness: 1, values: [{ x: hp.left, y: hp.top, scaleX: 0, scaleY: 0 }, { x: midpointx, y: midpointy, scaleX: 1, scaleY: 1 }, { x: vp.left, y: vp.top, scaleX: 0, scaleY: 0 }], autoRotate: true }, ease: Power1.easeInOut });
            }
        }
    </script>

 

this is a dynamic sprite of a plane and uses the house icon and vacation icon to build the path , the one control point is just the average of these points. Anyway no matter if i call this function for right or left ,the plane always moves from right to left- like in the "left" defined tween. the "right" tween just switches the insertion of the anchors points.. im a nood to GSAP so sorry for any misunderstandings.

Link to comment
Share on other sites

Hi @shaderbytes :)

 

Welcome to the forum. 

 

The problem is both of your conditionals are evaluating to truthy so both tweens fire. The second one instantly overwrites the first. The fix is a small change in your conditionals. Please try this:

if (direction === "right") {
  // do the right stuff
}
if (direction === "left") {
  // do the left stuff
}

// or you could just use if/else like this
if (direction === "right") {
  // do the right stuff
} else {
  // do the left stuff
}

 

If you have additional questions, a CodePen demo is the way to get the best answers. Here's some info about creating one:

Hopefully that helps. Happy tweening.

:)

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