Page 1 of 1

Need Help Distinguishing Between Character Front and Back

PostPosted: Thu Mar 15, 2012 1:25 pm
by Archaeaologist
Hello Everyone,

I'm rather new to this whole game development thing, and I was wondering if you guys could help me in what will undoubtedly be the first of many questions. My problem is this: I'm making a top-down Legend of Zelda kind of game, and I need to distinguish the front and back of enemies and my character (for shield placement or detection or whatever). Now, I know how to change their animation so it's related to the angle of their movement, and I'm sure I could extrapolate on that so that if their at some angle, their state has changed (though I do wonder if there are other ways to do it so that they could, say, walk backwards), but I don't know how to determine that they are behind the main character or the main character is behind them.

One way I can think to do it would be with wire-frame actors that have the character actor as their parent. If a character is in a certain wire-frame while the other character faces a direction, then the state of the first character is seen as behind the second character, and they'll behave accordingly. My main problem there, besides the volumes of coding I'd likely have to do, is I'd have to create many, many wire-frame actors to accommodate all the characters. Is there an easier way? Could I somehow distinguish between one part of a sprite and another?

Any help for this problem would be greatly appreciated.

Cheers.

Re: Need Help Distinguishing Between Character Front and Bac

PostPosted: Thu Mar 15, 2012 4:44 pm
by jimmynewguy
Something like this? Just check x/y values and the direction the enemy is facing.

For enemies being behind the player you could store their x, y, dir in a 2d array and loop through them. Wasn't sure if you needed that though. (It didn't make sense since the actually player would still see the enemies)

wasd will face the enemy, arrow keys will move the player, if the debug is red the player is behind the enemy.

And if this doesn't help, or isn't what you meant let me know

Re: Need Help Distinguishing Between Character Front and Bac

PostPosted: Thu Mar 15, 2012 5:47 pm
by Archaeaologist
That does help, actually. If I understand correctly, the code is first checking the direction the enemy is facing (which is based on animpos) and then checks the relative position of the player to the enemy. I'll have to play around with that concept and see how far I can adapt it.

Thank you very much.

Re: Need Help Distinguishing Between Character Front and Bac

PostPosted: Thu Mar 15, 2012 5:53 pm
by skydereign
Archaeaologist wrote:Now, I know how to change their animation so it's related to the angle of their movement, and I'm sure I could extrapolate on that so that if their at some angle, their state has changed (though I do wonder if there are other ways to do it so that they could, say, walk backwards), but I don't know how to determine that they are behind the main character or the main character is behind them.

For this I'd recommend setting a variable to hold the direction the player is moving in. Assuming you are going to add a few more animations, the use of animpos is going to get very annoying to deal with. With the variable, it is always set in the direction the player is facing, that way you can then compare with the position of the enemy, relative to the position and direction of the player.