Non-Blocking move to object

Started by edmundito, Fri 28/05/2004 21:12:02

Previous topic - Next topic

edmundito

I want to make my game so that when the player interacts with an object, the Player Character walks to that object without blocking.

However, If I use MoveCharacter(GetPlayerCharacter(), mouse.x, mouse.y) for example, there is a posiblity that the character moves to the wrong spot compared to MoveCharacterToObject because MoveCharacterToObject apparently moves the character to a spot below the object.

My question is... how can I find that spot below the object manually? any suggestions?

Blocking sucks :P
The Tween Module now supports AGS 3.6.0!

Mr Jake

erm, could you have the character walk to the spot then save its x,y to a file or print them on screen?? or is this not what you mean?

Scorpiorus

Do you mean

int object = GetObjectAt(mouse.x, mouse.y);
MoveCharacter(GetPlayerCharacter(), GetObjectX(object), GetObjectY(object)); ?

edmundito

Well, I have it on on_mouse_click, so I have something like: MoveCharacter(GetPlayerCharacter(), mouse.x, mouse.y);

And eventually it runs:
ProcessClick(x, y, mode);
when the char is right by the object

----

Do GetObjectX and GetObjectY get the walk-to point for the object? I though it just got the coordinates.
The Tween Module now supports AGS 3.6.0!

Scorpiorus

#4
Yeah, they return object coordinates but an object doesn't have a walk-to point as I remember. What MoveCharacterToObject does, is moving the character somewhere beneath objects position, like:

MoveCharacter(GetPlayerCharacter(), GetObjectX(object), GetObjectY(object) + 10);


EDIT:

I've just checked the exact offsets, they are +5 and +6 from the object's x and y respectively:
MoveCharacter(GetPlayerCharacter(), GetObjectX(object) + 5, GetObjectY(object) + 6);

edmundito

If we look at the screen from left to right, top to bottom. What if the character is before the object or above the object or both? wouldn't he walk in front or below the object...? It  wouldn't look right.
The Tween Module now supports AGS 3.6.0!

Scorpiorus

Yep, he would. At least that's how the MoveCharacterToObject command works.

Here is an example of alternative function to move the character to object:

function MoveCharacterToObject2(int CharID, int object, int distance, int blocking) {

   int sprite_slot = GetObjectGraphic(object);
   int sprite_w = GetGameParameter(GP_SPRITEWIDTH, sprite_slot, 0, 0);
   int sprite_h = GetGameParameter(GP_SPRITEHEIGHT, sprite_slot, 0, 0);

   int cX = character[CharID].x;
   int cY = character[CharID].y;

   int ocX = GetObjectX(object) + sprite_w/2;
   int ocY = GetObjectY(object) - sprite_h/2;

   int x = cX-ocX;
   int y = cY-ocY;

   int offsetX = 0;
   int offsetY = 0;

   if (x >= y)
      if (-x >= y) offsetY = -(distance+sprite_h/2); //top
      else offsetX = distance+sprite_w/2; //right
   else
      if (-x >= y) offsetX = -(distance+sprite_w/2); //left
      else offsetY = distance+sprite_h/2; //bottom
      
   if (blocking) MoveCharacterBlocking(CharID, ocX+offsetX, ocY+offsetY, 0);
   else MoveCharacter(CharID, ocX+offsetX, ocY+offsetY);
}

MoveCharacterToObject2(int CharID, int object, int distance, int blocking)

CharID - character to move
object - object to move character to
distance - how far from the object the character should stop (passing 0 will make the character stop once he touched object's graphic)
blocking - passing 1 will block the script while the character is moving

Pumaman

Scorpiorus is right, the built-in MoveCharacterToObject function simply does this

MoveCharacterBlocking(GetPlayerCharacter(), GetObjectX(object) + 5, GetObjectY(object) + 6, 0);

SMF spam blocked by CleanTalk