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
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?
Do you mean
int object = GetObjectAt(mouse.x, mouse.y);
MoveCharacter(GetPlayerCharacter(), GetObjectX(object), GetObjectY(object)); ?
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.
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);
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.
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
Scorpiorus is right, the built-in MoveCharacterToObject function simply does this
MoveCharacterBlocking(GetPlayerCharacter(), GetObjectX(object) + 5, GetObjectY(object) + 6, 0);