Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: plebeo on Wed 07/03/2007 21:36:39

Title: Character moving problem
Post by: plebeo on Wed 07/03/2007 21:36:39
There's two characters: a dog and a cat.

if the dog is on the right of the cat and bark at it, the cat must move left.

if the dog is on the left of the cat and bark at it, the cat must move right.

How can I realize that mechanism with the scripting?

Please hep me!
Title: Re: Character moving problem
Post by: Ashen on Wed 07/03/2007 21:55:41
Which bit are you after help with? The movement based on where the characters are in relation to each other is just a case of comparing their Character.x properties, e.g.:

  if (cDog.x < cCat.x) { // Dog is left of Cat
    // Animate dog and play barking sound
    cCat.Walk(cCat.x+10, cCat.y); // Move cat 10 pixels right
  }
  else { // Dog is right of Cat
    // Animate dog and play barking sound
    cCat.Walk(cCat.x-10, cCat.y); // Move cat 10 pixels left
  }


Have you tried something like that?

If you need help with the barking, you need to give a few more details about how you want it to work.
Title: Re: Character moving problem
Post by: plebeo on Wed 07/03/2007 22:16:22
Thanks Ashen.
It works well.

But now I need another thing

I give an example:

I have the cursor "bark".
The dog is on the left of the cat.
When I do "bark to cat", the dog must go near the cat (to its left), barks and then the cat must move right.

Then I move the dog  to the right of the cat  and I do "bark to cat" again. Now the dog must go near the cat (to its right), barks and then the cat must move left.

How I obtain this?
Title: Re: Character moving problem
Post by: Khris on Thu 08/03/2007 07:08:45
  if (cDog.x < cCat.x) { // Dog is left of Cat
    cDog.Walk(cCat-30, cCat.y, eBlock);        // added by me
    // Animate dog and play barking sound
    cCat.Walk(cCat.x+10, cCat.y); // Move cat 10 pixels right
  }
  else { // Dog is right of Cat
    cDog.Walk(cCat+30, cCat.y, eBlock);        // added by me
    // Animate dog and play barking sound
    cCat.Walk(cCat.x-10, cCat.y); // Move cat 10 pixels left
  }


Did you even *try* to figure this out yourself?
Title: Re: Character moving problem
Post by: plebeo on Thu 08/03/2007 09:05:09
It works!!
Thanks you Khris!!

Only one thing:

cDog.Walk(cCat-30, cCat.y, eBlock); is

cDog.Walk(cCat.x-30,cCat.y, e block);

you forgot the x.

However it works!!  ;D
Title: Re: Character moving problem
Post by: Khris on Thu 08/03/2007 16:21:29
Right, glad to help :)