AI and Attacking

Blitz3D Forums/Blitz3D Programming/AI and Attacking

Zach3D(Posted 2006) [#1]
Can someone show a simple code where there are 2 entities that will come and attack you (i can write my own code that tells how much damage and ect) but i need code to get them to walk up to you and attack, can anyone help me


Red Ocktober(Posted 2006) [#2]
are there any obstructions they must negotiate, or any roads they must follow... if not, then a simple pointentity() might do it, with maybe a rotateentity() to keep the pitch at 0... then start em moving towards the target...

... when they come within a certain distance() of the target, they can commence the attack...

i'm using something like this to train the guns on my subs at the selected target... the guns are ai controlled, and once the target is assigned and they have clearance to fire, they are on their own :)

if your enemies have to follow roads and stuff, i think that some sorta real ai (a* maybe) logic may need to be implemented...

--Mike


jfk EO-11110(Posted 2006) [#3]
some people may say this is a "write me a game" thread, but I think it's ok to ask for some help.
There are various ways to implement enemy attacks. Some are easy and simple, some are advanced and high AI.

A simple way is to check if the enemy can see the player (camera in a fps) and start shooting at him if so.

The enemy may move around in the map during his attacks. This may be along fixed "waypoints", or freely using pathfinding algorithms.

I would suggest not to use pathfinding since it's hard to make it right.

You may add a simple pseudo-pathfinding thing that allows the enemy to use multiple paths to try to get closer to the player, or to follow him.

That's firearms attacks. Physical attacks on contact may be a bit harder. Defensive "hits" is easy, but an offensive attack requires the enemy to run towards the player, probably leaving his waypoint lines.

this may be useful.
http://www.blitzbasic.com/codearcs/codearcs.php?code=505
http://www.blitzbasic.com/codearcs/codearcs.php?code=968


octothorpe(Posted 2006) [#4]
The general problem is solved by a State Machine. The literature on them is unfortunately quite convoluted, so I'll try to explain the basics.

Each actor keeps track of what it's currently doing. For this example, "idling", "approaching", and "attacking" will be the possible values of actor\state$.

In the actor's update routine, we switch (Select Case) on the state$.

case "idling" : check the distance from the player. If we're close enough to see him (insert line-of-sight check here,) set state$="approaching" else walk in a random direction

case "approaching" : make sure we're still close enough to see the player. if not, set state$ = "idling". if so, walk towards the player (insert pathfinding here.) if we're within attacking distance, set state$ = "attacking"

case "attacking" : make sure we're still close enough to attack. if not, set state$ = "approaching". if so, perform an attack animation.

Although it seems that you could simply switch on the distance, keeping track of state lets you get more complicated behaviours. For example, you could keep track of a timer variable for an attack animation and not make any distance checks or state changes until it has expired: once an actor has commited to an attack, he will follow through (unless interrupted by damage or something.)

Hope this helps!