Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: on Tue 20/07/2004 21:04:00

Title: are characters facing???
Post by: on Tue 20/07/2004 21:04:00
Hi everybody,

I would like to know if there is a simple way to know if a character is facing another character.

Something like isCharacterFacing(EGO,...)

I searched the help and the forum but that did not help...

Thank you in advance...

bye.
Title: Re: are characters facing???
Post by: Skio on Tue 20/07/2004 21:54:32
I'm afraid you'll have to use a more complex solution.
I'm thinking of cheking the characters' loops with character[CHARID].loop.

Suppose you have character A at the left of the screen and B at the right. To check if they are facing each other, type:

if ( (character[A].loop==2) && (character.loop==1) ) Display("We are facing each other!");

The problem is that you have to know from the beggining which direction the characters have to face to look each other.
Title: Re: are characters facing???
Post by: Pumaman on Tue 20/07/2004 22:02:44
And there's the other question about what you judge to be facing. What angle should count as facing the other character? Within 90 degrees? 45 degrees?

A basic check can be done as Skio suggests.
Title: Re: are characters facing???
Post by: on Wed 21/07/2004 09:08:09
First of all thanks for the answers.

So I have to write my own isCharacterFacing() function.

About the question of Pumaman,
it doesn't matter what I judge to be facing, it matters what AGS judges to be facing.

I want my function to be coherent with the FaceCharacter() function.

In other words, if isCharacterFacing(EGO,CHR) returns 1,
FaceCharacter(EGO,CHR) will not change EGO's loop.

That introduces my new question:

Does anybody know how FaceCharacter works?
Title: Re: are characters facing???
Post by: on Wed 21/07/2004 19:50:00
It's quite simple:
FaceCharacter (CHARID, int tofaceid);

Example:
FaceCharacter(EGO,MAN);
makes Ego look in man's direction, while man remains still.

For more information also see help file. search for "facecharacter"


Title: Re: are characters facing???
Post by: Hollister Man on Wed 21/07/2004 20:16:08
I would assume he meant how FaceCharacter works INTERNALLY...?

One other option is to set a variable every time you call facecharacter, so you can always check if the player is facing someone.
Title: Re: are characters facing???
Post by: Pumaman on Wed 21/07/2004 21:43:06
Well, you could do something like this:

function isCharacterFacing(int charid, int facingChar) {

int oldloop = characters[charid].loop;
FaceCharacter(charid, facingChar);
if (character[charid].loop != oldloop) {
  character[charid].loop = oldloop;
  return 0;
}

return 1;
}


which will determine whether FaceCharacter would have changed the loop or not.

Title: Re: are characters facing???
Post by: on Thu 22/07/2004 09:09:18
Thank you!

It worked perfectly.

IMHO this is a very clever suggestion!!!

Anyway, just to satisfy my thirst of knowledge, if anybody know how faceCharacter() works internally, please let me know! :-)

Thanks again!
bye!

Title: Re: are characters facing???
Post by: Radiant on Fri 23/07/2004 14:41:41
I believe you divide the screen into four sections with an X (not with a +), then check in which section the character you would face is standing (which is simple math of comparing x and y values) then turn to the relevant direction.
If you have eight directions, divide into eight sections instead.
Title: Re: are characters facing???
Post by: on Mon 26/07/2004 16:45:11
Thanks Radiant,

In the Week-End I wrote down a function that works in a similar way.

The center of the X is where character1 (the character who is supposed to face the other) is standing.

Once I know in wich quadrant the other character (character2)  is standing, I know if character1 is facing him checking character1's current loop.


I needed to do this because the solution suggested by Pumaman didn't work if called in the repeatedly_execute function.

Well... I think my problem is finally solved.

Thanks everybody.