Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: EnterTheStory (aka tolworthy) on Wed 26/12/2007 17:20:48

Title: characters sometimes slide instead of walking (SOLVED)
Post by: EnterTheStory (aka tolworthy) on Wed 26/12/2007 17:20:48
This is a problem that can be masked by using anti-glide mode, but that only hides the underlying problem, and makes for jerky uneven movement. I'd appreciate any ideas for solving the underlying problem:

(a) How to cancel 'AddWaypoint' without using 'StopMoving'

(b) Any other suggestions for what I'm doing wrong?

I have thirty characters walking randomly across the screen. I found that using "Walk" caused everything to slow down (due to path finding) so instead I use "AddWaypoint" and every two seconds I check if a character is on a walkable area. This runs much faster, but sometimes (maybe one time in twenty) the character slides instead of walking. The slide lasts for two seconds until the next walk update, then they walk normally again.

int dx = 40; if(GetGlobalInt(n + 100) !=1) dx = -40; // go right, or go left
int x = character[n].x + dx;
int y = character[n].y -10 + Random(20); // random element to avoid narrow lines

//--------------------------------------------- aim for a walkable area --------------------------------------------
cFloorfinder.x = x; cFloorfinder.y = y; // place invisible "floor finder" character  there
cFloorfinder.PlaceOnWalkableArea(); // find the nearest floor
character[n].StopMoving(); // Needed to avoid crash from ever increasing number of Waypoints.
character[n].AddWaypoint(cFloorfinder.x, cFloorfinder.y); // walk toward the new target


Even when the character walk properly there is a noticeable pause (just a couple of frames) at the 'StopMoving' command. That isn't nice, but I can probably live with it. The real problem is with not using the walk animation. "Antiglide" can stop the character at these points, but that causes more uneven walking.

Any ideas?
Title: Re: characters sometimes slide instead of walking
Post by: Creator on Thu 27/12/2007 12:12:30
Unless you have your other characters changing rooms use this in your room script:


function repeatedly_execute_always () {
    character[n].WalkStraight(Random(Room.Width), Random(Room.Height), eNoBlock);
}
}


That shouldn't slow down your game much (if at all) and should keep the player's walk cycle smooth.

I hope this helps.
Title: Re: characters sometimes slide instead of walking
Post by: EnterTheStory (aka tolworthy) on Thu 27/12/2007 19:07:45
Thanks, I'll try that!

Edit: I tried it, and it works, but being random, the characters kind of walk in circles, stop frequently, and backtrack all the time. The more that I try to add direction to them, the more I have problems with getting trapped against walls or in corners, or stopping every second while I assess their direction.

Another edit: After another few hours, I think I've cracked it. It was a question of trial and error, changing all the variables, trying new subroutines, until it more or less works. The characters now wander around smnmoothly, as if they have a life of their own, and it's fun to watch them. They still get confused and sometimes clump together, but it's not a big problem as most of them eventually separate again. 

The key to making it work was to rely on WalkStraight. So thanks, Creator! Your advice was much appreciated.