Character moving problem

Started by plebeo, Wed 07/03/2007 21:36:39

Previous topic - Next topic

plebeo

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!

Ashen

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.:
Code: ags

  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.
I know what you're thinking ... Don't think that.

plebeo

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?

Khris

Code: ags
  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?

plebeo

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

Khris


SMF spam blocked by CleanTalk