Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Sat 08/08/2020 08:51:21

Title: Stop player walking
Post by: Slasher on Sat 08/08/2020 08:51:21
Hi,

If a character interacts/looks etc  and it's during player walking the player should cease walking, even after interacting/looking until commanded to do...

At the moment it kind of looks silly.

Would like an 'if player walking' condition.. Then stop player temp. from walking.

Cheers

Title: Re: Stop player walking
Post by: Crimson Wizard on Sat 08/08/2020 16:00:23
Quote from: Slasher on Sat 08/08/2020 08:51:21
Would like an 'if player walking' condition..

Not sure if this is what you asking about, but there's Character.Moving property that is "true" when character walks or moves with Move command. There's similar property for an Object.
Title: Re: Stop player walking
Post by: zeta_san on Sat 08/08/2020 16:46:44
hi, this makes the character arrive at their destination to perform the action and can be interrupted

Code (ags) Select
  if (Verbs.MovePlayer(x, y)) {
Title: Re: Stop player walking
Post by: arj0n on Sun 09/08/2020 01:02:41
Quote from: zeta_san on Sat 08/08/2020 16:46:44
hi, this makes the character arrive at their destination to perform the action and can be interrupted

Code (ags) Select
  if (Verbs.MovePlayer(x, y)) {

That's specifically for when using the Tumbleweed template...
Title: Re: Stop player walking
Post by: ToeKnee on Mon 17/08/2020 17:57:34
I would use this to get that effect... may not be elegant but I just tried it and it will work;

To stop a moving Object/Char
Code (ags) Select

   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();


This works to stop a moving character or object - However the Character is not 'moving' in your example... but is 'walking'!

To stop a walking Character
Code (ags) Select

   int CharX=cEgo.x; int CharY=cEgo.y;
   Wait(1);
   if ((CharX==cEgo.x) && (CharY==cEgo.y))
      Display ("Wasn't Walking!");
   else {
      cEgo.Walk(cEgo.x, cEgo.y, eNoBlock, eWalkableAreas);
      Display("Was Walking, but is not now!");
      }


- Which stores the Characters x/y position on the screen, then waits 1/40th of a second, then checks for any change to either of those values (meaning it is walking). If there is a change, then make the character 'walk' to the 'current location' (effectively halting the character from walking - i.e: 'cancelling' the prior 'walk' location that it was going to and setting that to where it already is)
Title: Re: Stop player walking
Post by: Laura Hunt on Wed 19/08/2020 08:18:57
Quote from: ToeKnee on Mon 17/08/2020 17:57:34
To stop a moving Object/Char
Code (ags) Select

   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();


This works to stop a moving character or object - However the Character is not 'moving' in your example... but is 'walking'!

Character.Moving and Character.StopMoving also work with the Walk command.

From the manual:

QuoteExample:

cEgo.Walk(125, 40);
while (cEgo.Moving) Wait(1);

will move EGO to 125,40 and return control to the player when he gets there.

Also, you don't have to do "if(cEgo.Moving==1)". Simply doing "if (cEgo.Moving)" is enough.
Title: Re: Stop player walking
Post by: ToeKnee on Wed 19/08/2020 09:21:09
Quote
   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();

Laura, the manual says that but it does not work in gameplay once the Character is moving.
I just tried it again using the Moving and Stop Moving commands when you click on anything whilst the character is moving and it will not stop it.
My code works but those commands do not interrupt the normal 'walk' command that AGS has internally to move a character (probably has it's own blocking style)
Cheers. Tony
Title: Re: Stop player walking
Post by: Laura Hunt on Wed 19/08/2020 09:31:44
Quote from: ToeKnee on Wed 19/08/2020 09:21:09
Quote
   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();

Laura, the manual says that but it does not work in gameplay once the Character is moving.
I just tried it again using the Moving and Stop Moving commands when you click on anything whilst the character is moving and it will not stop it.

I have the following lines in my script and it works perfectly fine when the character is walking:

Code (ags) Select
function hLamp_Interact()
{
  if (cLadyW.Moving) cLadyW.StopMoving();
  cLadyW.SetWalkSpeed(1, 1);
}


You must be doing something else that's interfering with it, because the commands work exactly as expected (otherwise the game would crash, because you can't change walk speed while a character is moving).
Title: Re: Stop player walking
Post by: Khris on Wed 19/08/2020 09:54:25
I imagine that player.StopMoving() will always work but depending on where exactly you put it, might not get called during a blocking walk.
I put it in repeatedly_execute_always and it stopped the player perfectly fine during a standard blocking walk and a hotspot's walkto point approach (which is probably the same as a blocking walk internally).
Title: Re: Stop player walking
Post by: ToeKnee on Wed 19/08/2020 10:00:55
QuoteYou must be doing something else that's interfering with it

Yep, on re-checking the Stop Moving command was triggered on a Hotspot that has a 'WalkToPoint' set on it
- if I clear the WalkToPoint (0,0) - then the Character stops. Otherwise it (of course) keeps moving/walking to the Hotspot if I interact with it whilst character is moving.
Title: Re: Stop player walking
Post by: Laura Hunt on Wed 19/08/2020 10:06:58
Quote from: ToeKnee on Wed 19/08/2020 10:00:55
QuoteYou must be doing something else that's interfering with it

Yep, on re-checking the Stop Moving command was triggered on a Hotspot that has a 'WalkToPoint' set on it
- if I clear the WalkToPoint (0,0) - then the Character stops. Otherwise it (of course) keeps moving/walking to the Hotspot if I interact with it whilst character is moving.

Ah, that explains it, of course if the walk command is blocking then a workaround (such as using repeatedly_execute_always like Khris suggested) is needed. Glad it made sense in the end!