Page 1 of 1

How to face enemy actors?

PostPosted: Mon Mar 31, 2008 4:27 pm
by DST
I'm having trouble determining which way an enemy actor is facing. I use a variable (face) for the player, its based on right or left key down. But how do I calculate the same thing for an enemy?

If i'm not mistaken, the angle in ge starts at the far right, and 90 degrees is straight up.
so > < 180 only works for up and down, but not left to right.

i tried this:
Code: Select all
if (angle > 0 && < 90){do this}
if (angle > 90 && < 270){do this}
if (angle >= 270 && <= 360){do thing 1 again}


It didn't work at all!

I used xvelocity < or > 0 for flying actors, but that won't work for ground actors who are standing still.

Am I just really confused?

Re: How to face enemy actors?

PostPosted: Mon Mar 31, 2008 5:47 pm
by Fuzzy
You are misusing &&

try
Code: Select all
if (angle > 0 && angle < 90){do this}
if (angle > 90 && angle < 270){do this}
if (angle >= 270 && angle <= 360){do thing 1 again}


a full comparison must be done on both sides of && because it is possible to compare with two different variables. for example

Code: Select all
if(a > 0 && b > c)


for clarity(it doesnt hurt your code), i like to put the inside terms in brackets too. its easier to bug hunt.

Code: Select all
if( (a > 0) && (b > c) )


hope that helps.

Re: How to face enemy actors?

PostPosted: Mon Mar 31, 2008 6:20 pm
by Kalladdolf
also, don't forget, that if your actor stands still, the angle automatically drops to zero.

Re: How to face enemy actors?

PostPosted: Mon Mar 31, 2008 7:51 pm
by DST
That makes sense. Thank you.

Also, i'm thinking that if it is a single event, such as a timer or such, and it sets a face variable to 1 or 0, the variable will not be reset until there is an angle again, so the face will hold even if the actor is standing still. Provided he's moved at least once.

Another question while i'm at it:
I made a function for a collision, in which the rgb values of a different actor are specified; but they didn't transfer to the other actor.
Like this:

Code: Select all
void gethit()
{
health-=1;
visual.r=100;
visual.g=50;
visual.b=50;
}


Is this not possible in a function? I was able to use
Code: Select all
collide.health -=1;


That transferred to the collide actor just fine.

Re: How to face enemy actors?

PostPosted: Mon Mar 31, 2008 11:24 pm
by Fuzzy
No the function has to refer to the actor that owns the health. If you dont know until run time, then you will have to use a pointer to the actor.