Jump to content
Search Community

GSAP Draggable: How to dynamically block movement

Harold Bace 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

I am looking for a way to prevent dragging an object over other objects when using GSAP Draggable.

 

An object A that is dragged around must be "blocked" by another object B, so that A cannot overlap B.

 

I know how to detect "hits" with hitTest, but how do I prevent the dragged object from being moved over another object?

Link to comment
Share on other sites

What's your use case?

 

Trying to do that while dragging is really complicated. There is nothing to stop a user from moving their mouse through a "blocked" element. See this demo. It's using a collision detection library with responses, but the dragging is a little wonky because you can move your mouse through blocks, causing your draggable to jump around.

 

See the Pen c3a8ca782b69eedf260af82788d0084a by osublake (@osublake) on CodePen

 

 

That's a demo I quickly modified from this thread. It could be done better, but I don't have the time to rework it.

 

 

 

 

 

 

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