"Wandering" AI?

Hey all
I want to make some "Wandering " AI. I know the process but I don’t know how to do it

So I want the AI to pick a point on the navmesh and then go to it, repeating this until something happened (Ex: players starts shooting)

How is this done?

http://www.blender.org/documentation/blender_python_api_2_67_1/bge.types.KX_MeshProxy.html

you will need to pick a random vertices, and move your nav target object there, or create a object, place it there and then set your steering target

Do it like that
-make a navmesh and assign 2 or 3 points (where the ped will go)
-make 3 collision sensors which will sense collision with these points
-these will be connected to steering actuators which will send him to adjacent points

That’s how it will be wandering here and there

And now for 2nd part
-make a point where ped will take cover during shootout
-when player will shoot it will send message to ped
-ped will recieve message and steer to the cover point

It should work…
I’ll upload blend file for you tomorrow…
It’s actually 12 midnight here :wink:

Ok, I actually did that once, but I found having fixed points to move to made the game REALLY easy. I want to be able to randomly pick a point and move to it
I already have the shooting down, I just need moving randomly

@BPR: I’ll try programming it, although I only used expression controllers before and not the console.

Here is how I do it without using coding

TrackingorWandering.blend (533 KB)

Hope this is what you wanted

Fredstash

p.s I just used randoms connected to motion that would be overruled if it got close to the main character or the bullets causing it to track to the character or the cover respectively.

Ohh…you came very close to what I wanted!
But think about this: Wouldn’t it be strange to see a guy in a map moving like that?
Plus, it’s not actually “random”, although it sure does look like it…just press play a couple times and watch a minute of it, the cube will move the exact same way because the random sensor isn’t actually “random”

Thanks for the try, it almost worked :stuck_out_tongue:

oh, and I actually might use this in another game I’m making after my current


<b>for</b> mesh <b>in</b> object.meshes:
   <b>for</b> m_index <b>in</b> range(len(mesh.materials)):
      <b>for</b> v_index <b>in</b> range(mesh.getVertexArrayLength(m_index)):
              vertex = mesh.getVertex(m_index, v_index)

is close, you just need to use 1 random verticy instead of looping through all

then you use the navmesh position and rotation to turn local to global

Sorry, I have no idea what

is close, you just need to use 1 random verticy instead of looping through all

then you use the navmesh position and rotation to turn local to global

means…
how about doing something with…

bpy.ops.mesh.select_random(<i>percent=50.0</i>, <i>action='SELECT'</i>)[¶](http://www.blender.org/documentation/blender_python_api_2_71_release/bpy.ops.mesh.html?highlight=random#bpy.ops.mesh.select_random)Randomly select vertices

??

No bpy! :smiley:

No workings in game engine

mesh.getVertexArrayLength(m_index) = length of array

so a random number from 1->mesh.getVertexArrayLength(m_index)

would be a index value generated to select 1 verticity

to use in

vertex = mesh.getVertex((material index)), (your random number here))

untested and probably needs work


import bge
import random
cont = logic.getCurrentController()
own = cont.owner

mesh=own.meshes[0]
Length=mesh.getVertexArrayLength(0)
RandomNum= random.randint(0, Length)
vertex = mesh.getVertex(0, RandomNum)


Yeah I have noticed the same thing, but if you didm’t want it moving as consistently you could add delays (to the forward motion), but I don’t know how to make it more random.

Well, not exactly…there’s an error in line 1:“import bge” -> “from bge import logic”
even I knew that :smiley:

and I used always on a cube, didn’t work because cube didn’t snap to plane



Oh, and I tried adding a

 print (RandomNum) 

but that didn’t work :confused:

No, it’s cool. It’s a close call to actual randomness :slight_smile:

I coding though, there’s no such thing as actual randomness. it’s usually referred to as “pseudorandom” :stuck_out_tongue:

RandomNum= random.randint(0, Length)

I made RandomNum in the code, it does need work still I said,

Yeah I understand. I’ll try working off of your code for now

https://docs.python.org/2/library/random.html

I kind of glanced over the suggestions here, and figured id offer my two cents. but I guess its how “smart” you want yout wandering AI to be. To me, “wandering” means moving around aimlesslessley within a certain area unless it get triggered to attack. I feel that I have the samekind of AI. In my project, my AI spawns from a simple spawner,usally a bush or something and picks a random direcion to walk to. The AI wll also play a random animation as its doing whatever. The only correctins te AI will make is a change in direction or if it gets too far from its spawn…or if its aggroed enough to pursue the player…which it will still pursue only a certain distance from the spawner, and return to the spawn. I doont know much about nav meshes. But It depend on how smart you want your AI to be.

Yeah, that would be ideal for some situations. can you post a blend file of only the ai and nothing else? (use appending)
When I mean wandering, I mean moving without a cause, moving to random points on the map and randomly stopping to look around. I have all animations, just not code/logic