Ok, I need some enemy AI help. I’ve noticed a lot of people who ask for enemy AI help aren’t very specific, so instead of just saying “How do I make enemy AI,” I have a specific list of things I want the guy to do. My game is a third person shooter game if that makes any difference. I have all the characters modeled and the armatures connected and I’ve created all the actions (getting hit, aiming guns, throwing punches,etc). I don’t know THAT much about Python, but I know a little and I’m sure I can learn more. Here’s what I want the bad guys to do:
- I want some of them to stand still, and some of them to pace back and forth while they are waiting for me.
- Before they see me, they don’t know I’m there. Once they see me, they never “forget” they saw me.
- If they see me, attack (Aim at me and shoot).
- They are able to see me in front of them, above them, or below them, or any angle in between.
- If I’m above or below them, they aim accordingly.
- If I move, they move to follow me, or move their aim to keep shooting at me.
- They only shoot a limited number of times, stop briefly, they shoot again (They don’t just keep firing endlessly).
- If they need to, they will search for a better angle.
- They can’t see me through walls, boxes, ect.
I know this is a tall order, but I know it’s gotta be possible. if you have any knowledge about how to do even a small part of that list, that would be helpful. You guys haven’t let me down yet
The state system could really help you out here…When one of those occurrences occur, just change the state to one with the necessary action. You’ll just need to find the right sensor for the right response…
1.) random script with a range of howmany different actions you want them to do. if its just wait and search, then only two random choices and either send to different state or use a property to divide the actions. of course you do have to animatate there search and wait actions.
2.) i would use a ray, or radar to be pointion in +y axis with a certain distance. In if not in line of sight keep searching, If triggered use a new state,or prop, with a track to player.
3.)same as above, just more propertys and states, with a track to player.
4.)Same a 2,
5.) To acomplish this is tricky as i’ve tried to do this, but i cant get armature to play action acording to position of a target tracking method, i’ve tried drivers, but they only work in 3d view not real time. i guess you could make the arms and head apart from the main body and have the body track to play not 3d and arms along with a gun rig track in 3d to player.
6.) same as above.
7.) same as 1.
8.) definitely a script.
9.) more rays, In my game a have a double ray set up, one to sense you and search harder, but wont track to you unless there is line of sight, also when i shoot they look in my direction. and if they dont see me the keep searching.
10.) Good Luck.
here is a link of my game this is in it early stages. the ai as alot cooler now. Waiting to polish it up before i put it here. but you could download an exe in my youtube description.http://www.youtube.com/watch?v=8tDLl8lpCuU
Ok, that makes sense kind of. But how would I do a random script? When I said I know a little about Python, I mean I know a LITTLE about Python. Also the thing I don’t like about the ray sensor is that it only detects you if your directly in the line of sight. I kinda wanted to make it so they could see me from any angle, like if I was standing at a 45 degree angle to them.
use radar then, and for the random script use this.
import Mathutils as MT
cont = GameLogic.getCurrentController()
own = cont.owner
own[“random_prop”] = int(MT.Rand(1,5))
anim1 = cont.getActuator(“state_1”)
anim2 = cont.getActuator(“state_2”)
anim3 = cont.getActuator(“state_3”)
anim4 = cont.getActuator(“state_4”)
if own[“random_prop”] == 1:
if own[“random_prop”] == 2:
if own[“random_prop”] == 3:
if own[“random_prop”] == 4: