Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: AndreasBlack on Tue 29/08/2023 21:04:00

Title: Simulate 'Return To Monkey Island' run button with AGS Gamepad/Ags Controller
Post by: AndreasBlack on Tue 29/08/2023 21:04:00
It was one of the best ideas instead of double tapping, just holding in a button to run!  (nod) I'm unsure why this is not working. Perhaps it's the script of Double-Click that's blocking it somehow. Since i guess it should work in theory, right ???
Edit: I do undestand i need to reset it somehow, i'm just curious as to why this is not working, and how you would do it differently

function repeatedly_execute_always()
{
 
  if (mouse.IsButtonDown(eMouseMiddle) || gamepad.IsButtonDown(3))
 
  {
    player.SetWalkSpeed(10, 10); //Something like this perhaps,  but it's not working..
  }
 
Title: Re: Simulate 'Return To Monkey Island' run button with AGS Gamepad/Ags Controller
Post by: eri0o on Wed 30/08/2023 02:43:21
AGS characters can walk in two ways, I don't remember right now the right names but it's either non-gliding and gliding.

In non-gliding mode, the character walks a specific number of pixels (the walkspeed in this case) each specific number of frames (it's the delay of the walk animation). So to walk that specific number of pixels the pathfinding is broken in that specific number of steps - so if you change the walkspeed in the middle, which is the length of the step, it has to re-calculate the path to reach destination. This should be possible (at a cpu cost) but the way AGS does right now is it simply won't let you do this (I believe it gives an error saying that you shouldn't do this). So in the non-gliding mode, which is the default, the way to go to speed things up in the middle of the walk is to reduce the delay of the character - which won't alter the path, so it's allowed when the character is walking.

Now, in gliding mode, I don't remember what the walkspeed means right now, but in this mode the character can change the walkspeed mid walking.

Spoiler
Ah, if you are trying one of my previous experiments of the gamepad, I noticed now I never posted the last binary version that got merged in the forums, so in case you are already using ags4, it's better to wait for the next release to be posted in the forums.
[close]
Title: Re: Simulate 'Return To Monkey Island' run button with AGS Gamepad/Ags Controller
Post by: Crimson Wizard on Wed 30/08/2023 03:07:05
@eri0o, you are confusing some things, gliding and non-gliding modes are related only to how movement and animation are synced, but pathfinding works exactly same, and depends only on the starting walking speed.

SetWalkSpeed does not work while character is moving, at all. This is mentioned in the manual, and I believe it should print this to the warnings.log.

So you should change your logic somehow. If you want to change the speed while moving, then probably you may remember Character.DestinationX,Y in variables before calling SetWalkSpeed, and then order to walk again after.

Code (ags) Select
if (player.Moving)
{
    int dx = player.DestinationX;
    int dy = player.DesintationY;
    player.SetWalkSpeed(10, 10);
    player.Walk(dx, dy);
}
else
{
    player.SetWalkSpeed(10, 10);
}

Besides that you need to change the condition to make sure this is not called 40+ times per second, so only call this once if the walking speed is < max.

Code (ags) Select
if (player.WalkSpeedX < 10 && (mouse.IsButtonDown(eMouseMiddle) || gamepad.IsButtonDown(3)))
{
    if (player.Moving)
    {
        int dx = player.DestinationX;
        int dy = player.DesintationY;
        player.SetWalkSpeed(10, 10);
        player.Walk(dx, dy);
    }
    else
    {
        player.SetWalkSpeed(10, 10);
    }
}
Title: Re: Simulate 'Return To Monkey Island' run button with AGS Gamepad/Ags Controller
Post by: AndreasBlack on Wed 30/08/2023 15:27:22
Thanks, actually it was working i had blocked it myself with the character i was trying to do it with. Forgot i had speedrunning turned off just for that little room! (laugh)
I will try your code Crimson Wizard, thanks!