How to face enemy actors?

You must understand the Game Editor concepts, before post here.

How to face enemy actors?

Postby DST » Mon Mar 31, 2008 4:27 pm

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?
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: How to face enemy actors?

Postby Fuzzy » Mon Mar 31, 2008 5:47 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: How to face enemy actors?

Postby Kalladdolf » Mon Mar 31, 2008 6:20 pm

also, don't forget, that if your actor stands still, the angle automatically drops to zero.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: How to face enemy actors?

Postby DST » Mon Mar 31, 2008 7:51 pm

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: How to face enemy actors?

Postby Fuzzy » Mon Mar 31, 2008 11:24 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest