Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.
I'm having an issue with the AI design of the SHMUP game I'm building at the moment and was hoping the community might have some insight or input to help me out.
While planning out my AI procedures, I'm finding that for a lot of the functions I wan't to know the location of the player so that I can do things like:
Trigger things by proximity
Fly directly at the player
Shoot directly at the player
Avoid the Player
Is there a good method for allowing all instances of my Enemy class knowing at all times where my instances of Player class are?
My only real option I can see is passing a ptr to the player every time I update the enemy. And do that for each enemy I guess. I would also have to do that for each player when I implement multiplayer. Something like:
Ok, not exactly that far just yet, but in a way you hit the nail right on the head. I guess I'm essentially asking "How do I get my enemies to SEE the player?"
I suppose the easy answer would be what I presented in the OP, where you just update the enemy with the player location ever frame by passing it into the update function. Are there better algorithms for this? What other ways can I get my Enemies to see my Players?
My love is like a Haddoken, it's downright fierce!
I think what I did last time I came across this issue is store a target pointer. Essentially your Enemy class has a member pointer (or maybe an array, list or vector in your case).
Store 'em once and they're available whenever you need them. Varying targets are a bit more work as you have to remember to add the new instances where needed and avoid storing dead pointers.
May not be the best method, but it's all I can think of atm.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Maevik wrote:Ok, not exactly that far just yet, but in a way you hit the nail right on the head. I guess I'm essentially asking "How do I get my enemies to SEE the player?"
I suppose the easy answer would be what I presented in the OP, where you just update the enemy with the player location ever frame by passing it into the update function. Are there better algorithms for this? What other ways can I get my Enemies to see my Players?
Do you want the enemy to always know where the player is?(omniscient A.I)
or do you want the enemy to have a "sense of sight" and not know the player's position until he's spotted?
For the first one, it's pretty easy, you can just have the player's position global. (feel free to harp at me about bad programming practices )
The second one you would have something similar to a collision algorithm only the range would be the enemies line of sight or range of vision. You could then have some kind of flag for when the player's spotted and that could be relayed to other bots. The bots can have a targetLocation property (similar to what dandymcgee was saying), and within the sight algorithm you could have bots copy that property from other bots within range.
You could just store a pointer to a Player object and when you initialize the enemy either pass a pointer to the player object that allocates it or have a function which registers the Player object.
class Enemy
{
public:
Enemy(Player *player)
{
this->player = player;
}
private:
Player *player;
This would have the same output as passing the Player pointer to the Update function, but it is neater this way as you only have to send the object once.
thejahooli wrote:You could just store a pointer to a Player object and when you initialize the enemy either pass a pointer to the player object that allocates it or have a function which registers the Player object.
class Enemy
{
public:
Enemy(Player *player)
{
this->player = player;
}
private:
Player *player;
This would have the same output as passing the Player pointer to the Update function, but it is neater this way as you only have to send the object once.
Don't take this the wrong way, but how is that different from what I just said?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!