🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Just 2D AI ?

Started by
5 comments, last by DevLiquidKnight 21 years, 9 months ago
I was wondering if anyone can point me to a few locations about how to code and make effective 2D ai using C++ im mostly looking for like tricks and things that will ultimately increase the ai does anyone know where i could find these? or a website?
Advertisement
You need to be more specific about the specific tasks you want to accomplish with the AI, rather than just mentioning that it is in 2D? Are you wanting to perform pathfinding? Learning? Classification? More details will help forum members to provide a reasonable answer to your question.

Cheers,

Timkin
Im trying to come up with ideas for improving my AI this ai is a bird mind you. It so far hovers back and forth and if you are close enough to it in a radius it attacks u if u run so far out of another radius it goes back to hovering. The user uses a gun i might add in somthing so where it randomly moves when the bullet is so near.

[edited by - DevLiquidKnight on September 11, 2002 9:05:18 PM]
Okay, so you have a bird that changes state between attack and hover depending on the distance to the target and how it changes.

When determining what AI to use, or what ''tricks'' to employ, you need to have an idea of the behaviour/functionality of the agent imbued with the AI (in this case the bird).

What do you want the bird to do. Do you want it to follow the player, peck out his/her eyes, poop on them, talk to them, etc?

These things should all be a part of the design document for your game. They will help you clarify what outcomes you are trying to achieve and will generally determine the AI tools you need to implement to achieve those outcomes.

Once you''ve worked out what you want the bird to do we can help more with how to achieve that.

Cheers,

Timkin
I really just want to make the AI smarter then it is now so it can have a stronger advantage or equal advantage to the player.
I want to make the bird shoot feathers at the player
quote: Original post by DevLiquidKnight
I want to make the bird shoot feathers at the player


Okay... something we can work with!

Consider the bird shooting a feather at the player (nice idea by the way... does the bird end up bald when it's out of ammo???).
Let's assume that there is only one possible target and that the bird has two choices of weapons... a) it can fire a feather at the player; or, b) it can poop on the player if the player is beneath it.

So, the birds AI might include actions like:
MoveLandTakeOffEatSelectTarget   GetMyPosition   GetTargetPosition   SelectWeapon   AimWeapon   FireWeaponetc... 


Each iteration of the main game loop (or perhaps every few iterations if you want a slower reaction time for the Bird), the Bird checks to see if there is a valid target within range of it's weapons. If the range to the target is less than the maximum range of it's feather weapon, then the Bird's Target attribute would be set to the player. Otherwise, if there is no target in range, you could just leave the target attribute set to null.

If there is a valid target, another check can be made to see if the range to the player is small enough that the Bird could try using it's poop weapon. If not, then it just uses it's feather weapon, or perhaps decides to move closer without using any ammo. A check should be made to see if there is any ammo left. If there is, then the Bird can aim at the Player and fire it's feather (remembering to decrement the number of feathers remaining). If there aren't any feathers left, then the Bird should try to use its poop weapon by moving closer to the target. It might also consider doing this if the targets range is close to the poop weapon range but not close enough to enable a successful poop attack!

Perhaps after the bird has pooped several time it has to land and eat some grass, giving the player a chance to kill it safely. Birds eating grass might be scared into the air by an advancing (or shooting) player.

You can code all of this using a finite state machine. If you wanted some interesting complexity, you could use some Fuzzy Logic when analysing the distance to the target (from the bird). Alternatively, you could use probabilities for weapon selection. The chance of selecting either weapon might be zero (or nearly zero) if the target is outside of the maximum weapon range. Within this range, the chance of selecting the Feather weapon might be one at MaxFeatherRange and decrease to zero when range to target is zero (i.e., the target is below the bird). The chance of selecting the poop weapon might increase slowly for long ranges and be nearly one when the target is within poop range. Finally, there might always be a small chance that the bird will move rather than shoot, or do some other action (like eat). All of these probabilities should sum to one at any given range.

I hope this makes sense. I've sort of rushed this explanation as I am quite busy at the moment (sorry). If you have some particular questions about anything I have written, I would be happy to answer them for you.

Good luck,

Timkin

[edited by - Timkin on September 16, 2002 1:01:51 AM]

This topic is closed to new replies.

Advertisement