Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ncw911 on Mon 10/09/2012 22:38:55

Title: Help With Character.Walk/AreThingsOverlapping
Post by: ncw911 on Mon 10/09/2012 22:38:55
in room 1, i have it set up so when you push the spacebar the Character "STAR" is used as a bullet and moves upward untill it reaches the end of the screen or collides with an enemy,
most of my script works but im having problems with the - if (AreThingsOverlapping(Asteroid1.ID, STAR.ID)) { - code.

The Star will shoot, collide, and trigger the commands the main problem im having is that sometimes before the Star collides with the Asteroid it will stopmoving and wait, i cannot find out what causes this but here are some codes that ive been using that i think the problem belongs in, i want the STAR to not stop moving in the middle of a spacebar use of it
Asteroid1 = enemy
Darkenergy = another enemy with same problem
STAR = weapon
cEgo = Main character


//ROOM1
//Repeatedly Execute Script

if (AreThingsOverlapping(Asteroid1.ID, STAR.ID)) {

              Asteroid1.LockView(6);
              Asteroid1.Animate(0, 1, eOnce, eNoBlock);                                       
              Asteroid1.UnlockView();
             
              Asteroid1.x = Random(200);
              Asteroid1.y = (0); 
              Asteroid1.Walk(Asteroid1.x, 350, eNoBlock, eAnywhere);
             
}


if (AreThingsOverlapping(DarkEnergy.ID, STAR.ID)) {
   
              DarkEnergy.LockView(7);
              DarkEnergy.Animate(3, 1, eOnce, eNoBlock);
              DarkEnergy.UnlockView();
             
              DarkEnergy.x = Random(200);
              DarkEnergy.y = (0); 
              DarkEnergy.Walk(DarkEnergy.x, 350, eNoBlock, eAnywhere);             
             
}












// Codes Below in Global asc
//function keycode


if (cEgo.Room == (1)) {
  if (keycode == eKeySpace){
     

     
   
            if (GetGlobalInt(2)==100){
             
              cEgo.LockView(3);
          cEgo.Animate(0, 5, eOnce, eNoBlock);
          cEgo.UnlockView();
              STAR.x = (cEgo.x-1);
              STAR.y = (cEgo.y-12);
              STAR.Walk(STAR.x, 0, eNoBlock, eAnywhere);
             
    }
            if (GetGlobalInt(2)!=100) {
           
              cEgo.LockView(3);
              cEgo.Animate(0, 5, eOnce, eNoBlock);
              cEgo.UnlockView();
              STAR.x = (cEgo.x+2);
              STAR.y = (cEgo.y+2);
         STAR.Walk(STAR.x, 0, eNoBlock, eAnywhere);
             
}
}

}
Title: Re: Help With Character.Walk/AreThingsOverlapping
Post by: geork on Wed 12/09/2012 08:13:39
The problem with AreThingsOverlapping(thing1,thing2) is that it makes a rectangular check around the graphic: If there are any transparent regions in the sprite it will count those too.

This (http://www.adventuregamestudio.co.uk/forums/index.php?topic=26307.0) module should have you covered though, as far as I can tell.

It's possible to do this mathematically too, but the risk is that that only works with individual cases. Measuring the distance between the center of both characters, for example, only works if they are both perfect circles (otherwise modifiers are needed)

Just a quick note (because I like to be picky :P) instead of going
Code (AGS) Select
if (GetGlobalInt(2)==100){
//stuff
}
if (GetGlobalInt(2)!=100){
//stuff
}

You can do
Code (AGS) Select
if (GetGlobalInt(2)==100){
//stuff
}
else{
//stuff
}

As the else function would be called whenever GetGlobalInt(2) does not return 100