Animating only when character is in area scripting problem. [SOLVED]

Started by ZayanM, Tue 01/03/2005 01:25:26

Previous topic - Next topic

ZayanM

I would like character CLUCK to animate whenever character EGO moves near. I tried many times, but couldn't solve it. The character CLUCK would just switch to one frame, or it seemed like it, whenever EGO walked onto it.
Also, character CLUCK has an idle view that plays all the time (0)

Here is the last attempt I did in room repeatedly execute.

if (AreCharactersColliding(EGO, CLUCK) == 1) {
   SetCharacterIdle (CLUCK, 23, -1); 
   SetCharacterView (CLUCK, 24);
   AnimateCharacter (CLUCK, character[CLUCK].loop, 3, 1); }
   
else if (AreCharactersColliding(EGO, CLUCK) == 0){
   ReleaseCharacterView (CLUCK);
   SetCharacterIdle (CLUCK, 24, 0);
}

Since character CLUCK doesn't move I also tried making a region around the character that whenever EGO walks on to it, it animates, and when it walks out it stops animating. That didn't work either.

Help would be greatly appreciated. (Excuse the poor character names).  :)

Gilbert

The problem is, as you had mentioned, since CLUCK never moves, when EGO collides with CLUCK, the animation got restarted every gameloop whenever the two characters are still colliding (as the if (...=1) part of the code continues to execute every game loop) and the view got changed immediately when they go apart.
One way to get around this is to define a variable on top of that room's script to keep track of the collisions:
int colliding=0;

Then change that part of codes of repeated execute you posted to:
if (AreCharactersColliding(EGO, CLUCK) == 1) {
Ã,  if (colliding==0){ //not previously colliding
Ã,   colliding=1;
   SetCharacterIdle (CLUCK, 23, -1); 
   SetCharacterView (CLUCK, 24);
   AnimateCharacter (CLUCK, character[CLUCK].loop, 3, 1); }
   
} else if (AreCharactersColliding(EGO, CLUCK) == 0){
Ã,  if (colliding==1){//Just release from collision
Ã,   colliding=0;
   ReleaseCharacterView (CLUCK);
   SetCharacterIdle (CLUCK, 24, 0);
Ã,  }
}


Hope you understand the logic.

ZayanM

Thanks for the help though, I'm still having problems. Now the character CLUCK will animate when I go somewhere near it, but won't stop. It doesn't animate when I'm closely over or under it, but that may be the baseline problem in AreCharactersCollding. Thanks again, I would be grateful if you can solve the new problem.  :)

Gilbert

By the charactyer not-stopping, did you mean you just want the animation to play only once and non-repeating? In that case change that AnimateCharacter() line to:

AnimateCharacter (CLUCK, character[CLUCK].loop, 3, 0);

ZayanM

No, I would like the character CLUCK to stop animating when it is not in contact with EGO (baseline colliding).

Gilbert

Ah I think I know what's your problem now, the line in question is in red
if (AreCharactersColliding(EGO, CLUCK) == 1) {
Ã,  if (colliding==0){ //not previously colliding
   colliding=1;
   SetCharacterIdle (CLUCK, 23, -1); 
   SetCharacterView (CLUCK, 24);
   AnimateCharacter (CLUCK, character[CLUCK].loop, 3, 1); }
   
} else if (AreCharactersColliding(EGO, CLUCK) == 0){
if (colliding==1){//Just release from collision
   colliding=0;
   ReleaseCharacterView (CLUCK);
   SetCharacterIdle (CLUCK, 24, 0);
Ã,  }
}


It is because:
1. The delay of the idle view is set to 0, which from the manual: "Setting DELAY to 0 causes the idle view to be looped continuously when the character is not moving".
2. You set the idle view to 24, which is identical to what's used when the two characters met.

So the result is, when the characters went apart, CLUCK will continue (actually restarted animation) to animate with view 24 endlessly.
The solution is, depending on your actual need, change the idle view to an expected one, and/or change the idle animation delay.

ZayanM

Thanks. I didn't see that, that's why the animation played after the character EGO moved out. After changing the code the animation kept restarting, but I realized that the idle animation of the previous code worked. So I put the animation when characters colliding to an idle animation.

if (AreCharactersColliding(EGO, CLUCK) == 1) {
  if (colliding==0){ //not previously colliding
   colliding=1;
   SetCharacterIdle (CLUCK, 24, 0); }
   
} else if (AreCharactersColliding(EGO, CLUCK) == 0){
if (colliding==1){//Just release from collision
   colliding=0;
   ReleaseCharacterView (CLUCK);
   SetCharacterIdle (CLUCK, 23, 0);
  }


Thanks alot for all the help.  Couldn't have done it otherwise.  :)

SMF spam blocked by CleanTalk