Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rik_Vargard on Thu 16/01/2025 19:33:16

Title: [SOLVED] Player MOVE speed while playing animation.
Post by: Rik_Vargard on Thu 16/01/2025 19:33:16
Hiya,

I'm trying to have to player move from point a to point b, while playing an animation in NoBlock.

1: player walks to place
2: player starts animation in repeat & noBlock
3: player MOVEs to next place in Block

player.Walk (1300, 318, eBlock, eWalkableAreas);
player.Animate (21, 2, eRepeat, eNoBlock); // animation starts
player.Move (1925, 315, eBlock, eAnywhere); // moves from a to b
player.Walk (1921, 350, eBlock, eAnywhere);

Everything is working fine BUT the player moves from point a to b way too fast. Like "whoosh".

The question is: is there a way to make the MOVE part from point a to b to be much slower?

I'd like to avoid creating a new View if it's possible?

Thx! :)
Title: Re: Player MOVE speed while playing animation.
Post by: Crimson Wizard on Thu 16/01/2025 20:52:18
Have you tried changing speed before calling Move?
https://adventuregamestudio.github.io/ags-manual/Character.html#charactersetwalkspeed

Move's actual speed may be different from Walk if you have "movement linked to animation" setting. In which case the character's walking speed is restricted by animation speed during Walk, but not during Move.
Title: Re: Player MOVE speed while playing animation.
Post by: Khris on Fri 17/01/2025 12:55:44
If this won't work as desired, here's an extender function you can use:

void Move2(this Character*, int x, int y, float pixels_per_second) {
  // this always uses eBlock, eAnywhere
  float pixels_per_frame = pixels_per_second / IntToFloat(GetGameSpeed());
  float dx = IntToFloat(x - this.x);
  float dy = IntToFloat(y - this.y);
  float f = pixels_per_frame / Maths.Sqrt(dx * dx + dy * dy);
  dx *= f;
  dy *= f;
  int steps = FloatToInt(1.0 / f, eRoundNearest);
  float cx = IntToFloat(this.x);
  float cy = IntToFloat(this.y);
  for (int i = 0; i < steps; i++) {
    cx += dx;
    cy += dy;
    this.x = FloatToInt(cx, eRoundNearest);
    this.y = FloatToInt(cy, eRoundNearest);
    Wait(1);
  }
  this.x = x;
  this.y = y;
}

Just do
  player.Move2(1925, 315, 33.3); // moves from a to b at 33.3 pixels per second
Title: Re: Player MOVE speed while playing animation.
Post by: Crimson Wizard on Fri 17/01/2025 14:27:55
If we speak about alternate functions, there's a Tween module, where you can just do Tween.TweenPosition, which moves a character from one pos to another in a strictly given time.
Title: Re: Player MOVE speed while playing animation.
Post by: Rik_Vargard on Fri 17/01/2025 14:34:02
Thanks for your replies and so much for your code, Khris. (nod)

Well changing the walk speed just before the Move did the trick.
It is a bit confusing why we have to adapt the Walk speed and the Move speed.
Do they both calculate speed differently?

Well, cheers for the help as always! :)
Title: Re: Player MOVE speed while playing animation.
Post by: Crimson Wizard on Fri 17/01/2025 14:43:15
Quote from: Rik_Vargard on Fri 17/01/2025 14:34:02It is a bit confusing why we have to adapt the Walk speed and the Move speed.
Do they both calculate speed differently?

As I said in my previous reply:
QuoteMove's actual speed may be different from Walk if you have "movement linked to animation" setting. In which case the character's walking speed is restricted by animation speed during Walk, but not during Move.

You never mentioned if you have this setting on or not.
Title: Re: [SOLVED] Player MOVE speed while playing animation.
Post by: Khris on Fri 17/01/2025 14:55:32
Characters have a setting called AnimationDelay; this number specifies how many frames each walk cycle frame is displayed on screen.
If MovementLinkedToAnimation is true, the character only moves when AGS switches to the next walk cycle frame, which means that an AnimationDelay of 4 causes the character to only move every 4th frame, as opposed to every frame. This means that walking is 4 times slower than movement.

A perfect solution to this discrepancy requires you to 1) have a distinct walk cycle frame for each game frame (i.e. four or five times as many frames for each direction), 2) reducing the AnimationDelay to 1 (or 0?), and reducing the MovementSpeed to 1 (i.e. the number of pixels the character moves per walk cycle frame).
This is only feasible for high-res games though, and obviously a lot of extra work, unless you let Blender render your walk cycle frames or something.
Title: Re: [SOLVED] Player MOVE speed while playing animation.
Post by: Danvzare on Fri 17/01/2025 16:52:21
Quote from: Khris on Fri 17/01/2025 14:55:32Characters have a setting called AnimationDelay; this number specifies how many frames each walk cycle frame is displayed on screen.
If MovementLinkedToAnimation is true, the character only moves when AGS switches to the next walk cycle frame, which means that an AnimationDelay of 4 causes the character to only move every 4th frame, as opposed to every frame. This means that walking is 4 times slower than movement.

A perfect solution to this discrepancy requires you to 1) have a distinct walk cycle frame for each game frame (i.e. four or five times as many frames for each direction), 2) reducing the AnimationDelay to 1 (or 0?), and reducing the MovementSpeed to 1 (i.e. the number of pixels the character moves per walk cycle frame).
This is only feasible for high-res games though, and obviously a lot of extra work, unless you let Blender render your walk cycle frames or something.
Another solution would be to multiply the MovementSpeed by the AnimationDelay and set that as the new MovementSpeed before using the Move command, then setting the MovementSpeed back to it's original value after the fact. It could even be easily made into it's own function to automate the process.

Or just set MovementLinkedToAnimation to false. But then you run into another set of problems.  (laugh)  (Boy I wish that the MovementSpeed was a floating-point number.)



Quote from: Crimson Wizard on Fri 17/01/2025 14:43:15
QuoteMove's actual speed may be different from Walk if you have "movement linked to animation" setting. In which case the character's walking speed is restricted by animation speed during Walk, but not during Move.

You never mentioned if you have this setting on or not.
It's on by default and hidden away. So it's safe to say that yes it is.
Whenever anyone makes a post complaining about any problem involving moving characters in any shape or form, this setting is almost always the culprit, because people are unaware of it and its function.
Title: Re: [SOLVED] Player MOVE speed while playing animation.
Post by: Crimson Wizard on Fri 17/01/2025 17:13:00
Quote from: Danvzare on Fri 17/01/2025 16:52:21
Quote from: Crimson Wizard on Fri 17/01/2025 14:43:15
QuoteMove's actual speed may be different from Walk if you have "movement linked to animation" setting. In which case the character's walking speed is restricted by animation speed during Walk, but not during Move.

You never mentioned if you have this setting on or not.
It's on by default and hidden away. So it's safe to say that yes it is.
Whenever anyone makes a post complaining about any problem involving moving characters in any shape or form, this setting is almost always the culprit, because people are unaware of it and its function.

If THAT is a problem, then we may look for solutions.

1. A global setting could be made in General Settings (where it maybe will be more visible), defining the default value of this property for new characters.

2. This setting can be made "false" by default in order to force users to figure it out before using. Each template has its settings, that's something that is template's issue. But "Empty" template may retain editor's defaults.

3. The moving/walking rules may be clearly documented in the manual, in its own dedicated article.
I've been suggesting a "Game Features" section in the manual for the last several years. Started to write them, but the progress is very slow, because I'm busy with other things, and become unenthusiastic:
https://github.com/adventuregamestudio/ags-manual/wiki/_GameFeatures

Clearly something that this community members could do in the past 13 years since this engine became open source.
Title: Re: [SOLVED] Player MOVE speed while playing animation.
Post by: Rik_Vargard on Fri 17/01/2025 19:46:00
Hey thanks for the replies, guys.

At the end, it's just setting a movement speed for that moment for me and then back to the walking speed.

Quote from: Crimson Wizard on Fri 17/01/2025 14:43:15You never mentioned if you have this setting on or not.

Oh sorry about that, but yes, it is set on "true" by default

Quote from: Khris on Fri 17/01/2025 14:55:32This is only feasible for high-res games though, and obviously a lot of extra work, unless you let Blender render your walk cycle frames or something.

Yes, all my animations are rendered with Blender.