Sentry/Scout AI with or without python.

I’m trying to understand how to make an AI that will patrol on a path and will intercept/attack an opponent when in a specific range, and then move back to where it was. This is most likely possible only with python, I assume. I was also thinking that maybe the AI would try to attack and then try to get far away, and then attack again.
Any help on how this can be accomplished would be greatly appreciated.

First find out what a AI is.

I think you mean a character object.
A) choose the next waypoint (no waypoint left = continue with the first one)
B) trackTo the waypoint
C) move forward
D) if near waypoint -> A)

or
Setup an action to move the character on the path -> play the action.

What do you mean with intercept/attack and opponent. This is a vague objective. Logic can’t deal with unspecified objectives.

Near sensor, radar sensor, collision sensor

See patrol

“try”?

what is the different to that what you described earlier?

As you see the logic can be split up into smaller parts. The combination of small parts create the illusion of a complex behavior. The parts should be that small that the BGE can deal with it.
e.g.
“attack” means nothing to the BGE.
But “play the action “walk” from frame 1 to 50” and “move along Y” means something.

It does not really matter if you use Python or not. Python provides you much help when dealing with complex and dynamic tasks.
As before you should know what you are doing (at least what you want to achieve). The increase Power of Python increases to possibility to create much more mess.

Hint: Check out the raycast&detour

I hope it gives you a start.

Monster

When I said the AI will “intercept/attack an opponent”, I meant that if the target is within a certain range then the AI will track to the target, move towards it, and the begin shooting at it or hitting it, but not always trying to move towards the target.

Thanks for the other advice

When making an enemy, just like monster said, you have to decide exactly what you want it to do.
Then you have to decide how to do it.

So you two “states” (things to do):
Patrolling
Attacking

And how to do it?
Well. That depends on whether you do python or logic bricks.
I recommend python, as it allows you to do much more complex things. Like being seeing if the enemy can “see” the player.
I do python.
So what I do, is I create a property called “state” and then assign it an integer. With the integer representing a state, so in this case 1 would be patrol, and 2 would be attack.
Then you have a function for each state.
Patrol might track to position waypoint X where X is the previous waypoint+1 (that will have to be stored in a property)
As part of the patrol function it will check to see if the player is visible and in range. If it is then it goes to state 2. If it isn’t then it stays in state 1.
Attack is track to the player, and shoot. (and if he can no-longer see the player, then go back to patrol)

This is an example of a “finite state machine” (FSM), and is one of the simplest forms of real-time action AI’s

Other points to consider:
3 states might be best, patrolling, tracking to player and shooting.
FSM’s quickly get hard to debug, more than 5 states is almost unreadable under all the if/thens deciding which state to be in. Another type of AI is floating point (I can’t think of the proper name), where everything has a value, that is added to, subtracted from, multiplied by, the other values. Then it evaluates what to do based on the value. Do some reading on AI types.

AI is a complex topic, and knowing exactly what you need to do before you start is best.

If you want some code examples, I have some sneaky snippets that I can share with you. (to do with detecting the player, and deciding which state to take)