Hey, I was wondering if anyone knows if this is possible, where while you hold down the mouse button and the cursor mode is set to walk, the character moves to the current mouse position (if you've played Diablo II, you'll get what I'm talking about). I tried it but Roger just seems to stop until I release the mouse button.. I don't get it.
The pathfinder works out the path then starts moving along that path, it takes a little time to work it out, so if you keep telling the character to move every game cycle then it will just be working out paths and not moving, until you release the mouse.. you could only start moving toward the mouse when the button is pressed and then stop the character when it is released.. but that wouldn't update the target position as the mouse moves.. you sould just tell it to move toward the mouse every few steps when the mouse is down but that would probably be quite jerky :/ I can't think of a way that will do the pathfinding.
I got something working, but it's still kind of jerky:
int iMovCount = 0;
int iMX = 0;
int iMY = 0;
function repeatedly_execute() {
if(character[GetPlayerCharacter()].walking != 1 && iMovCount != GetGameSpeed())
iMovCount = GetGameSpeed();
if(IsButtonDown(LEFT) && GetCursorMode() == MODE_WALK) {
if (iMovCount == GetGameSpeed() && (iMX != (GetViewportX() + mouse.x) || iMY != (GetViewportY() + mouse.y))) {
iMX = GetViewportX() + mouse.x;
iMY = GetViewportY() + mouse.y;
MoveCharacter(GetPlayerCharacter(), iMX, iMY);
iMovCount = 0;
}
else iMovCount++;
}
}
and on on_mouse_click:
else if (button == LEFT) {
if(GetCursorMode() != MODE_WALK)
ProcessClick(mouse.x, mouse.y, GetCursorMode() );
}
If anyone has any input on how to improve it, that would be appreciated.
You could try using MoveCharacterStraight (unless you need it to avoid obstacles), because the path calculations are much simpler and it's a faster command. However, you still probably only want to call it once a second or something, not every game loop.
I figured it out :)
It works pretty well, except that there's one problem I think I cannot control. It seems that every time one calls MoveCharacter(...) the character stops moving, calculates path, and then walks again (or that's what the debug console is telling me) so it seems like my char has a leg injury of some sort every time a new coordinate is set. Is there any way to bypass this? Wouldn't it be a lot smoother, in general, if the character didn't have to stop moving if the character is already walking to calculate the new path? Just a thought. I don't know if it would make it more complicated, tho.
I'm not really sure what you mean. It has to calculate the path, or it wouldn't know how to get him to his destination.
I think he means that each time MoveCharacter is called the character stops for a game loop or something before continue, like:
MoveCharacterDirectBlocking()
StopMoving()
MoveCharacterDirect() :P
Hmm, MoveCharacter should preserve the current frame of the animation so this shouldn't be a problem. I'll take a look.
Quote from: Pumaman on Wed 17/12/2003 23:18:03
Hmm, MoveCharacter should preserve the current frame of the animation so this shouldn't be a problem. I'll take a look.
It's an effect kind of hard to see, but if you see it you know there's something funky going on.
on the debug console I get:
EGO: Stop Moving
EGO: Move character too coordinatex X, Y
every single time MoveCharacter(...) is called by my script
that's correct, however MoveCharacter should preserve the loop/frame of the character so that when they resume you shouldn't notice any glitches in the animation.
I was again looking at it closely, and I think it may have to do with the character slowing down every time there is a new MoveCharacter.... hmmm.