AreThingsOverlapping and RepExec

Started by KodiakBehr, Thu 05/12/2013 04:01:01

Previous topic - Next topic

KodiakBehr

Sorry for back-to-back messages on here, but I've engineered myself into a corner and would value a second opinion.

I want to be able to press a button and command an NPC to enter the nearest elevator.  Upon arriving at that elevator, the NPC will reappear in a lower section of the room and then exit the elevator by stepping forward.  Further complicating things, I have run out of regions to use and don't want to use the AGS 3.4 alpha yet.

What I've done is create an invisible object just above the upper and lower elevators that can only be colliding with an NPC if an NPC enters that elevator.  In the room, I say the following:

Code: ags


bool takingelevator = false;
 
function room_RepExec() {

    if (AreThingsOverlapping(cid, 1004) && takingelevator==false){
      takingelevator=true;
      character[cid].x=499;
      character[cid].y=365;
      character[cid].Walk(character[cid].x, character[cid].y+10, eBlock, eWalkableAreas); 
// taking it away from invisible object 1006
      takingelevator=false;
      }
    else if (AreThingsOverlapping(cid, 1006) && takingelevator==false){
      takingelevator=true;
      character[cid].x=2044;
      character[cid].y=365;
      character[cid].Walk(character[cid].x, character[cid].y+10, eBlock, eWalkableAreas); 
// taking it away from invisible object 1004
      takingelevator=false;
      }


It seems the eBlock doesn't supercede the rep_exec, because what happens is the character just ends up bouncing repeatedly between the two elevators and never walks out of them.

Is there a better method to accomplish what I'm trying to describe here?

Gilbert

As I couldn't really see what happened I couldn't comment on why the character didn't walk after teleporting, but are you sure that there is a walkable area for the character to walk down 10 pixels?
Also, check that whether the character still collides with the invisible objects after walking down that 10 pixels, if he still does he will still teleports to the other side for obvious reasons.

BTW, as you mentioned the elevator is to move from a top level to a bottom one (and vice versa), but looking at the coordinates used in the teleportation, the character is being moved to the left or to the right of the room. Do you just draw the two levels on the left and right sides of a horizontal scrolling room to represent the two levels?

Khris

The use of takingelevator doesn't have any effect here.
You're setting it to true, then set the character's position, then make them walk blocking, then set it back to false. No other code is ever executed during the time it's true (unless you checked for it in rep_ex_always).

If the character is overlapping either object in the very next frame, it is always false again, and the block is executed again.

So the problem seems to be that you aren't moving the character far enough away from the objects.

KodiakBehr

Very useful comments.  Thank you both.  I'll do some more experimenting.  I may need to redesign the game a fair bit, as I'm starting to think that testing non-player characters against regions and collisions against invisible objects is a more clumsy approach than testing characters against coordinates using GetAtScreenXY(mouse.x, mouse.y).

SMF spam blocked by CleanTalk