Skip navigation
Currently Being Moderated

collision detection and avoid

Oct 23, 2013 7:41 PM

Tags: #collision_detection #geometry #collisions #drag_dropping

The scenario is when dragging a item to a "fix and dangerous" item, it should detect the collision and move away from it. The collision detection already works fine, the problem is how to avoid collision.

Question: After collision detected, how to perform the avoid collision and move away from danger item?


I also post the question on Stack Overflow, which has more information. ion-and-avoid

  • Currently Being Moderated
    Oct 24, 2013 12:01 AM   in reply to jasonzhuang

    Have an 'invisible' rectangle that sitsover the object and extends beyond the visible area. Use that for collision detection - you will detect the collision before the object looks like it's colliding. You can then adjust the x,y position of the object to be further away from the object with which the collision is immenent.

    Mark as:
  • Currently Being Moderated
    Oct 25, 2013 12:07 AM   in reply to jasonzhuang

    A simple approach to this is to remember the x and y co-ordinate of the item being dragged. So on start drag, record the x,y position. whenever you receive a move or drag end event, check for a collision. If there's a collision, reset the position of the item to the last recorded position. If there's no collision, you can record the update x, y co-ordinates and continue.


    This will stop anyone dragging an item over a dodgy object.


    Googling " as3 collision avoidance" may help.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points