GML [SOLVED] Collision with a dropped item, some guidance needed

S

shrunkenmaster

Guest
I'm trying to figure out how I can drop an item and only have collision detected after I've moved off it, to avoid getting stuck on it.

At present, when the carried item (oCapPickup) is over the drop off point item (oCapGhost), the carried item returns to base and oCapDrop is created at the drop off point. The player (oRay) is getting stuck, which is not good. Any ideas?


oCapPickup object / collision event with oCapGhost:
Code:
if (other.image_index =3) {   
   
   score +=250;
       
   var _capdrop = instance_create_layer (other.x,other.y,"Pickup", oCapDrop);
   with (_capdrop) {
       image_index   = oCapPickup.image_index;
       image_speed = 0;
       }
                           
   with (other) {
   instance_destroy();
       }

   with (oRay) {
           {
           capcarrying = false;
           }
           whatcarrying();
       }
                       
   with (oCapPickup) {
       x = 213;
       y = 336;   
       }
               
   with (oGame) {
       capsleft -=1;
       oCapPickup.image_index = global.bincol;
       if (capsleft <=0) {
           instance_destroy(oCapPickup);
           }   
       }
}
Player oRay object / collision event with oCapDrop:
Code:
with (oRay) {
   
if (moveX !=0)  {
   if (place_meeting(x+moveX, y, oCapDrop)) {   
       repeat (abs (moveX)) {
           if (!place_meeting(x+sign(moveX), y, oCapDrop)) {
               x += sign(moveX);
               }
           else {
               break;
               }
           }
       moveX =0;
       }
   }
   

if (moveY !=0) {
   if (place_meeting(x, y+moveY, oCapDrop)) {   
       repeat (abs (moveY)) {
           if (!place_meeting(x, y+sign(moveY), oCapDrop)) {
               y += sign(moveY);
               }
           else {
               break;
               }
           }
       moveY =0;
       }
   }
}
 

SeraphSword

Member
Easiest way seems to be create a variable in your dropped object, something like willCollide = false. Make sure to set it in your with (_capdrop) code. Then you just add that to your collision code 'if' check. So you ignore the object while you are initially colliding with it and the variable is set to false, but once you are no longer colliding with it, you set it to true.
 
S

shrunkenmaster

Guest
Thanks for the reply. Would you be able to clarify further? I've tried wrapping the collision code in various places to check the variable but I'm not having any luck - still very much a beginner here.
 
S

shrunkenmaster

Guest
Managed to do this, if anyone cares. Seems rather clunky but it works.

Code:
if instance_exists (oCapDrop) {
   
   if ccc=true {
       if place_meeting (oRay.x,oRay.y,oCapDrop) {
           _capcollide=true;
           ccc=true;
           }
       
       if !place_meeting (oRay.x,oRay.y,oCapDrop) {
           _capcollide=false;
           ccc=false;
           }
   }
       
}

if instance_exists (oCapDrop) {
   with(oCapDrop) {
       if _capcollide=true and oRay.ccc=false{

           with (oRay) {
               if (place_meeting (x + moveX, y, oCapDrop)) {
                   while (!place_meeting (x + sign (moveX), y, oCapDrop)) {
                       x = x + sign (moveX);
                       }
                       moveX = 0;
               }
   
               if (place_meeting (x, y + moveY, oCapDrop)) {
                   while (!place_meeting (x , y + sign (moveY), oCapDrop)) {
                       y = y + sign (moveY);
                       }
                       moveY = 0;
                   }
               }                   
       }
   }
}
 
Top