are characters facing???

Started by ilFaro, Tue 20/07/2004 21:04:00

Previous topic - Next topic

ilFaro

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.

Skio

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.
Î'νδρων Επιφανων Πασα Î"η ΤαφοÏ,

Pumaman

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.

ilFaro

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?

menazerus

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"



Hollister Man

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.
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

Pumaman

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.


ilFaro

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!


Radiant

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.

ilFaro

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.

SMF spam blocked by CleanTalk