Jump to content
Search Community

ThrowProps, Can you set max velocity?

ecsancho 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

Hi  I'm wondering if there's a way to set a max velocity? I'm using a proxy div and having my elements respond the proxy.x positions the problem is with a slight flick sends my elements flying off screen because of the start velocity is a large number so I think restraining the max velocity will solve this.

 

Here's my setup

let proxy = $("<div>");
Draggable.create(proxy, {
  trigger: box,
  throwProps:true,
  onThrowUpdate:function(){
  	//code for elements.x = this.x
  },
  snap:function(endValue) { 
                return Math.round(endValue / 80) * 80;
            }
});

 

Link to comment
Share on other sites

No there is no setting to set maximum velocity. You can instead set  max and min duration and resistance. Check throwProps under 'Config object properties' https://greensock.com/docs/Utilities/Draggable

 

What you are doing might be done without Draggable, you can use ThrowPropsPlugin directly to track velocity. And use Physics2DPlugin.

 

https://greensock.com/docs/Plugins/ThrowPropsPlugin

 

https://greensock.com/docs/Plugins/Physics2DPlugin

  • Like 3
Link to comment
Share on other sites

Yep, @Sahil is exactly right - you probably only need ThrowPropsPlugin because it can track the velocity of any property of any object, and you can just do a regular throwProps tween whenever you want. You'd define an "end" value inside the throwProps object to do your custom snapping logic. 

ThrowPropsPlugin.track(object, "x"); //I'm not quite sure what you're tracking

TweenMax.to(yourOtherObject, 1, {
  throwProps:{
    x:{
      velocity:ThrowPropsPlugin.getVelocity(object, "x"),
      end: function(endValue) { 
            return Math.round(endValue / 80) * 80;
        }
      }
   }
});

 

That assumes you want a particular duration (1 second in this case), but you can use ThrowPropsPlugin.to() if you want that duration to be automatically calculated based on the velocity. 

 

I doubt you even need Physics2DPlugin. 

  • Like 3
Link to comment
Share on other sites

I need to track velocity because I want to do a certain animation when velocity hits certain ranges, I just didn't include the code in my sample. I believe this might work as long the initial velocity is not a large number. I'll give it try. Thanks for the responses!

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