Author Topic: Lossless Collisions  (Read 1036 times)

ashes999

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Lossless Collisions
« on: Wed, Dec 14, 2011 »
I've noticed a couple of things about collisions:

- The objects that collide acquire velocity directional to the collision, even if they were standing before
- The objects that collide move, even if you set their velocities to zero after collision
- Collision velocity is "lossy," despite the default bounce coefficient being one, things slow down over time.

Is there a way to remove these limitations and come up with a "perfect" lossless collision, i.e.:

- Collided objects don't move or change velocity
- Velocity doesn't degrade per collision

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Lossless Collisions
« Reply #1 on: Wed, Dec 14, 2011 »
The transfer of velocity etc is performed by the separation part of the collision. You can over-ride this or just use FlxG.overlaps instead, and then you'll get raw collision data and not the separation part.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

ashes999

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Lossless Collisions
« Reply #2 on: Wed, Dec 14, 2011 »
@photonstorm collide was instantaneous; overlap seems to be laggy and glitchy. Sometimes the collision happens, sometimes not; sometimes, the objects "stick" for a second before the velocities reverse.

It looks like the problem is the collision method is called multiple times per frame. So there's no easy way to just reverse velocities and stuff. Sucks. Oh well.

Cheers though, I solved it using overlap :)
« Last Edit: Wed, Dec 14, 2011 by ashes999 »

ashes999

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Lossless Collisions
« Reply #3 on: Fri, Dec 23, 2011 »
The next problem I have is that overlap doesn't work with isTouching(DIRECTION). How can I solve this problem? Going back to collide doesn't work; ball velocity eventually reaches zero.