[Solved] Make NPC walk to a location, and then animate, without blocking

Started by Britishgaming, Sun 05/08/2012 19:12:27

Previous topic - Next topic

Britishgaming

Hi there!

I want to have a character walk to a specific spot, and then play an animation.

That's easy when I set the walking animation to eBlock, but that
pauses the pace of the game. Not what I intended.

However, if I set it to eNoBlock, the character disregards the walking
command, and immediately plays his animation from the wrong location.

I need something between the cDave.walk and cDave.animate commands.
But, for the life of me, I can't figure out what.

Any suggestions welcomed! Thanks

Andail

In Repeatedly execute, you check whether the character reaches the destination, and then run the animations when that is true.

Like:
Code: ags

function whatever()
{
cCharacter.Walk (100, 100, eNoBlock);
}
function room_RepExec()
{
if (cCharacter.X == 100){
 cCharacter.Animate ();
}
}


You can also include something to make sure it only happens once, so that the character doesn't animate every time it touches that coordinate.

Crimson Wizard

This really depends on what you are trying to achieve. For example if there are other events possible during character movement (like he is chased by enemies and may be caught) then it really should use room_RepExec function.

In simplier cases this may be enough:
Code: ags

function whatever()
{
   cCharacter.Walk (100, 100, eNoBlock);
   while (cCharacter.Moving) Wait(1);
   cCharacter.Animate(...);
}

Also, there was a module that did this easier, made by Khris, but I forgot its name :/.

Britishgaming

Hey guys

Thanks for your suggestions. Wizard, sadly yours doesn't quite work - the wait command blocks the mouse cursor in the same way as eBlock.

Andail, that's quite a good idea. It will take some tweaking, but it might work.

I'll leave this marked as "Unsolved" for the time being, in case someone has a more elegant solution.

Oh, and in answer to your question Wizard - my character has a partner, and I want the partner to be able to do his animations (like getting out of a car or walking over to inspect something) without stopping the game entirely.

Ta

Khris

My module only works for the player character and mouse click interactions.

As far as how to do this, Andail explained it fine. There's no better method; the position of the player has to be checked inside one of the available rep_exe's.
I'd probably use a region. Those can be turned on and off, so I don't need an additional variable.
To find out whether the character reached the target, check the region at their feet:
Code: ags
// inside room_RepExec
  Region*r = Region.GetAtRoomXY(cDave.x, cDave.y);
  if (r.ID == 1) {
    r.Enabled = false;
    cDave.Animate(...);
  }

Britishgaming

Sorry for the bump/late reply, but it would be rude not to say thanks to everyone. Khris - your's worked great. Yours is a nice backup, Andail, if I'm overloaded with regions.

Thanks again. I'll set the title to Solved now.

SMF spam blocked by CleanTalk