Anyone know of any AI scripts they can point me to that has been released for us to use? The simple Path finding in blender isn’t enough for the games I intend to make. Thanks.
Only the public school system in the US. ha I made a joke.
Use your own nifty logic to control the steering actuator,
A* and Navmeshes are smart… it’s just aiming them that is the tricky part.
Google Eraser bot…?
First off, the pathfinding in blender is not exactly simple, and works quite well(Better than anything I could come up with(Speed wise and accuracy(Using A* pathfinding btw, maybe they use D* or whatever its called :P))). In anycase, assuming you don’t just want the AI to move around, you could have a go at making your own. If thats the case, then no-one will provide you with a script that will work specifically for your game. For this you will have to know python(I would suggest learning Python even if this isn’t the case). There’s a great article on Pathfinding here: http://www.policyalmanac.org/games/aStarTutorial.htm
If you just want the AI to move around and follow something though, I would suggest using the Inbuilt system. It has lots of settings, I would suggest playing with them all.
Edit: Just realised that you never specified what you want the AI to do, that might help
What do you mean with “AI script”?
AI is a large large thing. An AI for holding a natural conversation with you is going to suck at trying to drive a car. An AI for one FPS will suck at another.
AI’s are game-specific, so I’m afraid I’m going to have to say: Learn to program, it’s the only way.
What you can do for AI on a general level is just examples. For your own project no one else can make a functioning AI than yourself.
Don’t be intimidated by the “AI” expression. Code a basic thing like “move forward, if there is a wall, stop” and you already have an AI. Start simple and build up from it.
i know only finite state machine (FSM)
i read also some other , but not sound anything good(from what i understand)
i make almost nothing with FSM (i make a giant mess with classes), but i’m sure is a good system.
you can also use it in the bricks that is already done .
the purpose is that first of any other check (if x>y etc) there the state , that should desribe already a bit of things, so many checks bercome completely avoidable in short…
as say, rather than use different obj , you use ever the same but with logic “cleaned”
I mean simple patrolling, attack, flee, and chase.
Patrol = choose points on a nav navmesh and move it’s nav target there,
attack = Change/move navmeshmesh target to player, if vision cone is breached, only for X iterations(so it can lose the player if it does not spot them)
Flee = Change navmesh target to designated “repair station” or medical kit or dead end with cover etc.
Chase = Set nav mesh target.
all of this just requires a tiny bit of python
if own[‘Spot’] = True:
navmeshtarget.worldPosition = Enemy.worldPosition
if own[‘Count’] =<0:
(if you see the player, move the target and set a counter)
Have you tried to learn from tutorials on the internet?They are plenty of tutorials to get you started.You could use that information along with premade scripts to make a videogame.
What exactly do you mean with patrolling? What objects and events are involved?
When should it happen? How should it happen?
The same questions belong to the other tasks.
I mean the AI patrols set way points back and forth with a limited view and detection range. If it spots the player, It chases them and attacks once it gets close enough. Once it’s health hits a certain low value, it flees.
Well then you’re basically requesting a tutorial for a whole finished game? Just search for tutorials on navmesh path finding, RVO obstacle avoidance, states (for patrolling, spotting attacking,…), and a basic health system synced with attacking.
navmesh game.blend (981 KB)Study my game and you will know how to do it.The enemies do the flee.Click on the enemies and study the logic bricks.Click on the player and the player’s empty and study it’s logic bricks.d to move forwards.A to rotate vehicle.T to rotate turret and g to rotate it the other way.s to fire bullets.
What exactly is the “AI”? Is it a character?
We know know what you expect on patrolling. I suggest to look for an FSM (finite state machine).
One state is “Patrolling”
You wrote it should do:
“set way points back and forth with a limited view and detection range”
You need to detail it a bit more until the you get logic that the BGE understands. E.g. A waypoint is an empty. The logic adds a new waypoint when … at …
Then you need the other states “… attack, flee, and chase”.
With similar descriptions.
And you need the transitions between the states:
“If it spots the player, It chases” - means it changes to state “casing” (I guess from state “patrolling”)
" attacks once it gets close enough" means when in state “chasing” transit to state “attacking”
“Once it’s health hits a certain low value, it flees.” transit to “fleeing” (I guess from any state)
You can implement an FSM with the build in state system.
I hope this gives you the right idea.
i guess the problem that i have with FSM is because i make too few states ,
this allow to have “conditions convulted” (the condition to change state)
that become the problem since these condition here not reusable(too state dependend) , and so start the mess…
this is a FSM using string , (is more readable and more explicit than a class)
running on the enemy obj,
note “patrolling” (convulted) and “find waypoint” that is a fake state:
import bge import random, mathutils def drawObOb(ob1,ob2,rgb): bge.render.drawLine(ob1.worldPosition, ob2.worldPosition,rgb) def findObs(own, key): return [i for i in own.scene.objects if key in i and own !=i ] def seeOther(own, other): return True if own.getDistanceTo(other)<20.0 and own.getVectTo(other).y>0.0 and own.rayCastTo(other) in [other, None] else False def main(cont): own = cont.owner if not "init" in own: own["init"] = 1 own["steer"] = cont.actuators cont.activate(own["steer"]) setState(own, "find waypoint", vel=5.0) player = findObs(own, "player") state = own["STATE"] steer = own["steer"] target = steer.target #print(dir(steer)) ##### HP if own["HP"] < 1.0: own["HP"] += 0.001 own["HP"] -= 0.00015 * steer.velocity # COLLISION ground = cont.sensors["CollisionGround"].positive hit = cont.sensors["CollisionEnemy"].hitObject if ground: cont.activate(steer) else: cont.deactivate(steer) if hit and own.getVectTo(hit).y>=0.0: own.applyMovement((0.01, 0.01, 0), 1) # .. STATES ######################### if state == "find waypoint": setState(own, "patrolling", vel=5, tar=random.choice(findObs(own, "waypoint"))) ######################### elif state == "patrolling": if own["tick"]%30==0 and own["HP"] > 0.8 and seeOther(own, player): setState(own, "follow player", vel=15, tar=player) elif own.getDistanceTo(target) < 10.0: setState(own, "find waypoint", vel=5) ######################### elif state == "follow player": drawObOb(own,player,[1,1,0]) if own["HP"] < 0.2: setState(own, "find waypoint", vel=5) elif own.getDistanceTo(player) < 5.0: setState(own, "attack player", vel=25.0) elif own.getDistanceTo(player) > 30.0: setState(own, "find waypoint", vel=5.0) ######################### elif state == "attack player": drawObOb(own,player,[1,0,0]) if own["HP"] < 0.2: setState(own, "find waypoint", vel=5.0) def setState(own, state, vel=-1, tar=-1): own["STATE"] = state if vel != -1 : own["steer"].velocity = vel* random.uniform(0.7,1.3) if tar != -1 : own["steer"].target = tar def mainD(cont): try: main(cont) except: bge.logic.endGame() raise
You guys can give me code, but I don’t understand what to do with it. I am not a seasoned programer. I know how to make simple, non-blender related programs.
Make a navmesh, set it’s target to a empty that is no collision,
In the empty have this
Always ----and—copy property target from ai
Open the text editor
Click templates?(not sure if this is the name)
You will have some code at the top that is all important
Cont=getCurrentController or something
Own = cont.owner
Then you can do stuff like
In Ai body navmesh target
Target = scene.objects[Own[‘target’]]
So basically Ai spots player, feeds player as navmesh target by moving the empty.