Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: TheJBurger on Wed 08/07/2009 04:10:28

Title: Multiple Clicks + Collision Detection [SOLVED]
Post by: TheJBurger on Wed 08/07/2009 04:10:28
In a certain section of my game there are multiple cylinder devices dropping from the ceiling that can smash the player. My collision detection consists of detecting if the player is on the region the smasher comes down on, and if the smasher object is below a certain y position. If both are true, I run a "kill char" code.

This sequence works, except it has one odd problem. When the character walks and stops directly below the smasher before it falls, he dies when it comes down. However, if the player walks below the smasher, and then repeatedly clicks to the other side (but fails to make it), the player gets instantly transported to the other side when the smasher falls and the kill code refuses to run.

Here is my code in RepEx:

 if (Region.GetAtRoomXY(player.x, player.y) == region[2] && oSmasherRight.Y > 160 && IsGamePaused() == 0) {
    // if (center7phase == 7) {
      if (player == cDeltaSix) {
       player.StopMoving();
       DieDeltaSix(Maintenance);
       Wait(40);
       }
 }


My Die code is this:

function DieDeltaSix(Death2 param) {
 int animspeed=2;
 player.LockView(VDELTADYING);
   player.Animate(player.Loop, animspeed, eOnce, eBlock);
 //player.LockView(DIE);
 Wait(40);
 Autosave(Load);
 }


Also, the room is a horizontally scrolling room, so I don't know if that may take into effect on it.
Title: Re: Multiple Clicks + Collision Detection
Post by: R4L on Wed 08/07/2009 05:38:05
Maybe it's the clicking that is blocking the function from running? I know that when you use Interact or Look, it runs a blocking function if you set it that way...

Just a possibility.
Title: Re: Multiple Clicks + Collision Detection
Post by: Gilbert on Wed 08/07/2009 06:33:44
I think this could be a quirk in the path finding algorithm, as the character shouldn't have teleported.

What is the walking speed of the character? Are you sure that the walkable area is wide enough for him to not trigger odd behaviour due to too narrow areas?
Title: Re: Multiple Clicks + Collision Detection
Post by: TheJBurger on Wed 08/07/2009 07:01:52
Walk speed is 7 and animation speed is 3.

The walkable area is about 110 pixels in width and 40 pixels high. The character can be stopped directly in the middle of the walkable area and when the smasher falls, he still gets teleported to the closest available walking area.

Doh, I also forgot to say I disable walkable areas when the smashers are down (otherwise the players could walk into them and die when the smashers are stopped). That's probably why he's teleporting, but I don't know how.

This is that code which is also in RepEx:

    if (oSmasherRight.Y < 125) {
    RestoreWalkableArea(2); //
  }
  if (oSmasherRight.Y >= 125) {
    RemoveWalkableArea(2);
  }
  if (oSmasherLeft.Y < 125) {
    RestoreWalkableArea(3); //
  }
  if (oSmasherLeft.Y >= 125) {
    RemoveWalkableArea(3);
  }
Title: Re: Multiple Clicks + Collision Detection
Post by: Gilbert on Wed 08/07/2009 07:54:11
I don't know, but I think that is quite possibly be where the problems are from.

When a character is moving and you disable the area he's current on weird things (like teleporting) can happen.

Try to stop the character first before disabling the areas. To prevent interruption of his walk when he's walking outside of that particular area add some 'if' checkings:

   if (oSmasherRight.Y < 125) {
   RestoreWalkableArea(2); //
 }
 if (oSmasherRight.Y >= 125) {
   if (GetWalkableAreaAt(cDeltaSix.x,cDeltaSix.y)==2) cDeltaSix.StopMoving();
   RemoveWalkableArea(2);
 }
 if (oSmasherLeft.Y < 125) {
   RestoreWalkableArea(3); //
 }
 if (oSmasherLeft.Y >= 125) {
   if (GetWalkableAreaAt(cDeltaSix.x,cDeltaSix.y)==3) cDeltaSix.StopMoving();
   RemoveWalkableArea(3);
 }
Title: Re: Multiple Clicks + Collision Detection
Post by: TheJBurger on Wed 08/07/2009 08:46:32
Cool! That code did the trick.

Since it was a scrolling room though, I had to add a GetViewportX() in there for the GetWalkableAreaAt. Everything seems to be working now.

Thanks for the help!
Title: Re: Multiple Clicks + Collision Detection [SOLVED]
Post by: Gilbert on Wed 08/07/2009 09:02:59
Ah yes, I always forget about the Viewport thingie.  ;D

This certainly is a cause of many game bugs not easy to detect, too.