Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Cerno on Sat 30/01/2016 10:23:40

Title: idle animation while talking
Post by: Cerno on Sat 30/01/2016 10:23:40
Hello all.

I have a flying character and use the Idle animation to make the wings move while the character is standing still in mid-air.

A few problems I have:
Title: Re: idle animation while talking
Post by: Cerno on Wed 23/03/2016 20:48:01
It's been a while since I posted this question and I finally found a nice solution that I just wanted to share in case anyone stumbles over the same issue.

I finally went with splitting off the wings to a separate character, so now I have one character for the body and one for the wings.
The body character now only does the talking motions (mouth movements and arms gestures) while the wings can just go flapping constantly.

Now the next problem was tackling the visible jerk that occurs when AGS goes from the movement cycle to the idle cycle and starts each animation at frame 0 no matter where the other one left off.
It was suggested elsewhere that the two-character solution would best be implemented by having the second character follow the first one using the FollowCharacter function.
From my understanding that does not solve the jerk problem since the wings need to switch from walk cycle to idle cycle as well.

So I wrote this script to allow for smooth flapping. Just took the character for a spin and so far it seems to work really well.
I may extend this to other cases where a character talks and moves his body at the same time (think Stan from Monkey Island)

If there are better ways to go about this, please let me know.

Code (ags) Select
//PARAMETERS START
int DELAY = 10;  //wing animation delay
int LOOP_LENGTH = 5;  //number of frames in the wing animation loop
//PARAMETERS END

int offset = 0;
int timer = 0;
bool following = false;

function repeatedly_execute_always()

  //make sure the wings are always in the same room as the character
  if (cChar.Room != cWings.Room)
  {
    cWings.ChangeRoom(cChar.Room);
  }
 
  //make sure the follow function is only called once (not sure how much overhead this produces when called every frame)
  if (!following)
  {
    cWings.FollowCharacter(cChar, FOLLOW_EXACTLY, 0);
    following = true;
  }
 
  // cycle through the wing animations
  if (timer == 0)
  {
    cWings.Frame = offset;
    offset = (offset + 1) % LOOP_LENGTH;
    timer = DELAY;
  }
  timer -= 1;
 
  //make sure the wings always appear in front of the body
  cWings.Baseline = cWings.y + 1;
 
  //copy all character traits to the wings
  cWings.Loop = cChar.Loop; //copy character facing direction (make sure the animation definitions match)
  cWings.ManualScaling = cChar.ManualScaling; (in case the character is scaled manually)
  if (cWings.ManualScaling)
  {
    cWings.Scaling = cChar.Scaling;
  }
  //todo: add more character traits here
}