How to make an animated chicken character run in the background? (SOLVED)

Started by GazJ, Tue 26/08/2008 23:29:21

Previous topic - Next topic

GazJ

Hi

My problem is as follows I want a chicken to walk around at random in the background of a room.  It walks a short distance then decides to change direction etc.  Imagine the dog in 'Beneath a Steel Sky' if you have played it.

I have all the walking animations for the chicken there is just the four directions Up, Down, Left and Right.

I have experimented by putting this just to get started off:

function room_RepExec()
{
  cChicken1.Walk(129, 177, eNoBlock);   // from its starting position of 69, 177

}

But this just makes the chicken walk on the spot.  The chicken only walks when an interaction event is called in the room.

I am a bit flummoxed with this scripting task so any ideas would be very gratefully received.

Makeout Patrol

I'm not going to type this whole thing out here, but, assuming that there aren't any functions in the manual that can do this for you, I would do it like this:

Code: ags

function room_RepExec(){
  if(cChicken1.Moving() == false){  // only call this function if the chicken is not moving

    int destination = random(0, X);
     // I don't have the manual before me, so I'd check the syntax here. Depending on how large the area you 
     // want the chicken to be tearing about is, you'll want to change the range.

    // If AGS supports 'switch' structures, those would be a better way to go about doing this, but this will work either way:
    if(destination == 0){
      cChicken1.Walk(X, Y, eNoBlock);
    }
    // Replace X and Y with the co-ordinates of one of the points you want the chicken to move to. Put in else structures for 
    // each of the other possible values of 'destination' with different points that the chicken can get to.

  }
}


How this works is that, once the chicken has reached its destination and stopped moving, the game generates a random number, and, depending on what number results, sends the chicken to a different point. You can set up as many or as few points as you like, and your chicken will dart between them at random. If you like, you can even have a case where the chicken stops for a moment and takes a breather.

Fade to White

Yeah, your problem was that Character.Walk cancels any previous .walk command, so within a RepEx loop the caracter stops and then starts moving each cycle, therefore they never manage to move off the spot.
You need to add an :

if (!cChicken1.Moving){

...

}

check to make sure this doesn't happen.

GazJ

Thanx for both of your replies.

That explains why the chicken was walking on the spot and the :

if (cChicken1.Moving == 0)

will also sort out the problem of when the chicken stops at the edge of a walkable area.

Now I am going to try and work out how to make the chicken move away when the player comes near it.

SMF spam blocked by CleanTalk