Animate a walking character in the background

Started by DiegoHolt, Mon 12/08/2024 05:05:28

Previous topic - Next topic

DiegoHolt

Hello, I'm just a couple months into AGS and have a newbie question (haven't found anything about it searching the forum)

How can I make a character walk in the background without blocking the game? I mean, eNoBlock isn't working since it jumps to the next code line.

I'm trying to do something like Melee Island map, when you're practicing for the Sword Master. I need characters to walk around from one point to another randomly.

Thanks in advance.

Eon_Star

Hi,

There's a way to make caharacters walk / move in the background. I am not sure how to make them walk in an endless "loop" but you can try this out.

Say you have a city street and building at each side of the screen. You could draw two walkbehind areas on each side and put the cahracters behind these areas. You can use the code in "RoomAfterFadeIn" function to make them walk in the background.


Here is the script:


"Character.AddWaypoint(int x, int y)Tells the character to move to (X,Y) directly, after it has finished its current move. This function allows you to queue up a series of moves for the character to make, if you want them to take a preset path around the screen. Note that any moves made with this command ignore walkable areas.

This is useful for situations when you might want a townsperson to wander onto the screen from one side, take a preset route around it and leave again.

Example:

cSomeguy.Walk(160, 100);
cSomeguy.AddWaypoint(50, 150);
cSomeguy.AddWaypoint(50, 50);tells character SOMEGUY to first of all walk to the center of the screen normally (obeying walkable areas), then move to the bottom left corner and then top left corner afterwards.
"


I know there are better scripters here. I think they can help you further.

I wanted to give you the start.


Have a nice day/night.  ;)


Khris

#2
This problem can be solved the same way that basically any other non-blocking sequence is solved: by using the repeatedly_execute / room_RepExec function to check whether the current non-blocking command has finished.

In your map room:

Code: ags
function room_RepExec() // this function has to be linked to the room event
{
  for (int i = 3; i <= 5; i++) {
    if (!character[i].Moving) {
      Point* p = PickRandomTarget(character[i]);
      character[i].Walk(p.x, p.y);
    }
  }
}

Now put this function further directly above in the same script:
Code: ags
Point* PickRandomTarget(Character* c) {
  // pick a random target
  int ri = Random(3) + 1; // 1-4
  Point* p = new Point;
  // determine coordinates
  switch(ri) {
  case 1: p.x = 123; p.y = 45; break; // 123,45 is first target
  case 2: p.x = 234; p.y = 56; break; // 234,56 is second target
  // case 3 and 4 here
  }
  return p;
}

Eon_Star

Thanks Khris.

I did not try that script.

However when I try to use the "room_RepExec" function it does not work in general.

This script of your can be tried out.

 :-D

Snarky

Annoyingly, room_RepExec has to be linked to the room event in the event panel, IIRC.

DiegoHolt

Thank you all for taking your time to reply! While I was waiting for an answer yesterday I came up with this:

function room_RepExec()
{
      if (IsTimerExpired(2))
   {
        cCarla.Transparency = 0;
        cCarla.Walk(75, 86, eNoBlock, eAnywhere);
        SetTimer(6, 85);
   }
         if (IsTimerExpired(6))
   {
        cCarla.Walk(135, 113, eNoBlock, eWalkableAreas);
        SetTimer(9, 120);
   }
         if (IsTimerExpired(9))
   {
        cCarla.Walk(113, 155, eNoBlock, eAnywhere);
        SetTimer(7, 80);
   }
         if (IsTimerExpired(7))
   {
        cCarla.Transparency = 100;
   }
}

I have no programming skills whatsoever so it's quite a challenge for me to "tie it with wire" like we say here when you patch something up.

That code up there is just a small walking test, but it worked just fine for what I need to do.

I'll try your code Khris, but I'll surely have to study it in detail to understand some things there.


Thanks again, people.  :-D

SMF spam blocked by CleanTalk