Problem with AreThingsOverlapping (SOLVED)

Started by Akumayo, Sun 05/02/2006 18:07:53

Previous topic - Next topic

Akumayo

I'm building a game where when two characters touch, an interaction is run.Ã,  This worked fine for many rooms, but when I get to a certain point, something goes wrong.Ã,  In one room, I have 30 AreThingsOverlapping interactions in the room's repeatedly_excecute.Ã,  However, while the first 15 run smoothly, the last 15 are buggy.Ã,  Sometimes the characters pass directly through one another, and the interaction is never run.Ã,  The interaction is still there though, becuase after running through one another several times, it will be run.Ã,  Any suggestions for a fix?
"Power is not a means - it is an end."

Gilbert

Most of the time it's probably some glitches with scripting, more probably problem in if {} else, etc. nesting, i.e. we probably can't help much if you don't post the related piece of code.

Akumayo

I'm pretty sure it's a problem within the engine, it only happens ever so often now, becuase I've shortened the number of interactions from 30 to 13.  It still happens sometimes though, the characters just fly through one another.  Here's the full code:
Code: ags

if (AreThingsOverlapping(BADA, BALL) == 1) {
  BallHitsPaddle();
  if (cBadb.Room != 6) {
    cBadb.ChangeRoom(6);
    cBadb.x = ((Random(13) + 1) * 20);
    cBadb.y = ((Random(6) + 1) * 20);
  }
  else if (cBadc.Room != 6) {
    cBadc.ChangeRoom(6);
    cBadc.x = ((Random(13) + 1) * 20);
    cBadc.y = ((Random(6) + 1) * 20);
  }
  else if (cBadd.Room != 6) {
    cBadd.ChangeRoom(6);
    cBadd.x = ((Random(13) + 1) * 20);
    cBadd.y = ((Random(6) + 1) * 20);
  }
  else if (cBade.Room != 6) {
    cBade.ChangeRoom(6);
    cBade.x = ((Random(13) + 1) * 20);
    cBade.y = ((Random(6) + 1) * 20);
  }
  else if (cBadf.Room != 6) {
    cBadf.ChangeRoom(6);
    cBadf.x = ((Random(13) + 1) * 20);
    cBadf.y = ((Random(6) + 1) * 20);
  }
}
if (AreThingsOverlapping(BADB, BALL) == 1) {
  BallHitsPaddle();
  if (cBadc.Room != 6) {
    cBadc.ChangeRoom(6);
    cBadc.x = ((Random(13) + 1) * 20);
    cBadc.y = ((Random(6) + 1) * 20);
  }
  else if (cBadd.Room != 6) {
    cBadd.ChangeRoom(6);
    cBadd.x = ((Random(13) + 1) * 20);
    cBadd.y = ((Random(6) + 1) * 20);
  }
  else if (cBade.Room != 6) {
    cBade.ChangeRoom(6);
    cBade.x = ((Random(13) + 1) * 20);
    cBade.y = ((Random(6) + 1) * 20);
  }
  else if (cBadf.Room != 6) {
    cBadf.ChangeRoom(6);
    cBadf.x = ((Random(13) + 1) * 20);
    cBadf.y = ((Random(6) + 1) * 20);
  }
}
if (AreThingsOverlapping(BADC, BALL) == 1) {
  BallHitsPaddle();
  if (cBadd.Room != 6) {
    cBadd.ChangeRoom(6);
    cBadd.x = ((Random(13) + 1) * 20);
    cBadd.y = ((Random(6) + 1) * 20);
  }
  else if (cBade.Room != 6) {
    cBade.ChangeRoom(6);
    cBade.x = ((Random(13) + 1) * 20);
    cBade.y = ((Random(6) + 1) * 20);
  }
  else if (cBadf.Room != 6) {
    cBadf.ChangeRoom(6);
    cBadf.x = ((Random(13) + 1) * 20);
    cBadf.y = ((Random(6) + 1) * 20);
  }
}
if (AreThingsOverlapping(BADD, BALL) == 1) {
  BallHitsPaddle();
  if (cBade.Room != 6) {
    cBade.ChangeRoom(6);
    cBade.x = ((Random(13) + 1) * 20);
    cBade.y = ((Random(6) + 1) * 20);
  }
  else if (cBadf.Room != 6) {
    cBadf.ChangeRoom(6);
    cBadf.x = ((Random(13) + 1) * 20);
    cBadf.y = ((Random(6) + 1) * 20);
  }
}
if (AreThingsOverlapping(BADE, BALL) == 1) {
  BallHitsPaddle();
  if (cBadf.Room != 6) {
    cBadf.ChangeRoom(6);
    cBadf.x = ((Random(13) + 1) * 20);
    cBadf.y = ((Random(6) + 1) * 20);
  }
}
if (AreThingsOverlapping(BADF, BALL) == 1) {
  BallHitsPaddle();
}
if (AreThingsOverlapping(BBREAKA, BALL) == 1) {
  score ++;
  cBbreaka.x = ((Random(13) + 1) * 20);
  cBbreaka.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}
if (AreThingsOverlapping(BBREAKB, BALL) == 1) {
  score ++;
  cBbreakb.x = ((Random(13) + 1) * 20);
  cBbreakb.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}
if (AreThingsOverlapping(BBREAKC, BALL) == 1) {
  score ++;
  cBbreakc.x = ((Random(13) + 1) * 20);
  cBbreakc.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}
if (AreThingsOverlapping(GBREAKA, BALL) == 1) {
  score += 2;
  cGbreaka.x = ((Random(13) + 1) * 20);
  cGbreaka.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}
if (AreThingsOverlapping(GBREAKB, BALL) == 1) {
  score += 2;
  cGbreakb.x = ((Random(13) + 1) * 20);
  cGbreakb.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}
if (AreThingsOverlapping(GOBREAK, BALL) == 1) {
  score += 3;
  cGobreak.x = ((Random(13) + 1) * 20);
  cGobreak.y = ((Random(6) + 1) * 20);
  BallHitsPaddle();
}


I think maybe the engine just couldn't handle 30 interactions at once maybe?
"Power is not a means - it is an end."

Gilbert

Since I'm not sure what you're aiming for, can't give any constructive idea yet. Can you check if the function BallHitsPaddle() is working properly?

Akumayo

It is, I've never had problems from it.  I think, as I said earlier, that the engine might just not be able to handle 30 AreThingsOverlapping checks at a time, running at 40 a second might not be sufficient given that the characters are only overlapping for one game cycle, the engine might just miss them hitting, becuase as I said originally, it will run the function, but only every four or five collisions does the engine respond.
"Power is not a means - it is an end."

Gilbert

Well I think it's possibly because you didn't read the manual thoroughly:

Quote
Returns 0 if they are not overlapping, or the overlapping amount if they are. This amount is an arbitrary scale, but 1 means they are just about touching, all the way up to higher numbers for more overlappingness.

So, remove all the '==1' (unless they're really necessary, but I don't think so) and try again.

Akumayo

Ahh, so something like:
Code: ags

if (AreThingsOverlapping(BADA, BALL) >= 1) {
  BallHitsPaddle();
  if (cBadb.Room != 6) {
    cBadb.ChangeRoom(6);
    cBadb.x = ((Random(13) + 1) * 20);
    cBadb.y = ((Random(6) + 1) * 20);
  }
}


Would return if they were overlapping at all?
Thanks for the help also!
"Power is not a means - it is an end."

Gilbert

I'd rather:
Code: ags

if (AreThingsOverlapping(BADA, BALL)) {
  BallHitsPaddle();
  if (cBadb.Room != 6) {
    cBadb.ChangeRoom(6);
    cBadb.x = ((Random(13) + 1) * 20);
    cBadb.y = ((Random(6) + 1) * 20);
  }
}


But yes >= 1 should work also, it's just not necessary.

Akumayo

Right-O then, thanks for all your help!  My game continues!
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk