Jump to content
Search Community

Collision Detection, etc

Emax 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 need to implement collision detection on circular elements.  Determining whether 2 objects collide is pretty straight forward (sum of radii is less than distance between centers), but I can't seem to find much on the topic of changing the objects velocity and direction after the collision.  I've written code like this in years gone by, but I was hoping I'd be able to save some time by not recreating the wheel.  Even better would be a plugin that handles multiple collisions, and sets the objects on to their new paths with their new velocities.  Any help is appreciated.

 

 

Link to comment
Share on other sites

Sorry, we don't have any tools that do all that for you. GSAP wasn't meant to be a full-blown physics engine.

There are certainly tools like VelocityTracker that will assist you in getting the current velocity of objects so that you can figure out new velocities after a collision.

 

You might get some ideas from demos like: 

 

See the Pen vNwRdO?editors=0010 by osublake (@osublake) on CodePen

 

Calculating new velocities for 2 circles that hit each other from opposing angles at different speeds is going to require a fair amount of trig / physics that is beyond the scope of what we can help you with.

  • Like 1
Link to comment
Share on other sites

I'm not worried about the trig.  I'm just trying to figure out the simplest path to coding the billiard balls effect, and since I just spent $99 on GreenSock, I was hoping to make use of it.  So, if I use an "event callback", and write the code to detect ball collision, along with the code to reset ball velocities, is it possible to update the tweened element to a new velocity vector?  If not, that means doing my own animation and not using GreenSock at all, in which case I just paid $99 for something I can't use.  Then there's the rotation aspect... shoot.

Link to comment
Share on other sites

I’m so sorry to hear about the disappointment. I just issued a full refund. Your satisfaction is guaranteed. We’re passionate about having happy customers around here and I’m really bummed to hear that you didn’t feel like the membership was worth the cost. 
 
And yes, if your goal was to have GSAP do all the physics logic in your game including collision detection and bouncing, etc., that’s not really what the animation engine was designed for. A physics engine is a totally different beast, and there are some significant down sides to physics engines that make it poorly suited for a tween-based system. Each has its pros and cons, of course. You could definitely use GSAP’s ticker to run whatever logic you want, but that doesn’t solve the problems you referenced regarding collision detection, bouncing, imposing boundaries, etc. I’m very sorry if we communicated things poorly on the site and gave you the wrong impression about what GSAP is for. 
 
To answer your question about the event callback, you could definitely do the collision detection in an onUpdate (or TweenLite.ticker.addEventListener()) and then just create a new tween at that point when you're changing direction. GSAP has auto-overwriting enabled by default so you don't even have to kill the old tween (though you could if you want). 
 
Happy tweening (or physics-engining) :)
  • Like 2
Link to comment
Share on other sites

Thank you very much.  I've been coding for almost 50 years and I will say you guys have an outstanding product.  If, later on, I need what it offers I will come back.  Also, your customer support appears to be excellent.  Thank you!

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