Collision detection while dragging.

Started by Leon, Fri 07/11/2008 23:41:45

Previous topic - Next topic

Leon

I'm trying to figure out how to detect if an object is colliding with any other object while dragging. The objects can only be dragged horizontal or vertical and are positioned in steps of 25px.

The dragging isn't the problem, the detection is. What I have in the room script.

Code: ags

function noloopcheck drag(Object*o)

....

while(mouse.IsButtonDown(eMouseLeft)){
    
    if (o.Graphic == 1) {
       if (mouse.x - xa > 100 && mouse.x - xa < 175) {
          fX = IntToFloat((mouse.x - xa) / 25);
          iX = FloatToInt(fX, eRoundNearest);
          o.X = iX * 25;
        }
    }

....

    Wait(1);
  }
}

function objTile1_Interact()
{
  drag(object[1]);
}


I've tried to add  if (Object.GetAtScreenXY(o.X + 50,o.Y) == object[t]) in a loop to check all t's
I've tried to add if (object[1].IsCollidingWithObject(object[t])) in a loop to check all t's
I've tried if (PPColliding.OWithAnything(objTile1)) while dragging.

What I'm trying to achieve is that whenever an object collides with any object on screen, it stays at it's current location (no more dragging) until the blockage is cleared.

The area the objects are moving in is a grid of 6 x 6 and the code above is used to make the object 'snap' to grid (working as planned). I've also tried to use and 2d array to keep track of the occupation of the grid cells but that also wouldn't workout (the 2d array does though.).

What am I overlooking trying to detect the collision? Maybe there are other ways to get the job done?

Any suggestion is welcome.

Anyone any suggestion?

[update] Now that I come to think of it: none of the objects will ever overlap. Is there a way to detect any collision? Some kind of PPColliding.OWithAnything(OWithAnything) that can be put in the repeatedly_execute() ?
Ultimate Game Solutions - Because there is a solution for everything

Khris

I'm pretty sure that no rep_ex code is executed while the game is inside the while loop.
You could try rep_ex_always.

Having said that, if the objects snap to a 6x6 grid, using a 2d array and checking how far the object can go at the beginning of the drag is better.

SMF spam blocked by CleanTalk