AI (Villagers)

I’m very experienced in VB, but not so much with python. I get the basics of python code, but I want to expand my knowledge into the object oriented part of programming. Here, I’ve made a simple character with some basic actions(run, jump, walk, idle, jump, ect.)

I’ve animated him, and made them work in the GE with different keys using logic bricks. I want to make a small village with these guys in it, all of them walking around, milling around, and randomly selecting different paths to go around, with different actions. So, a simple village scene, with these guys either idling or walking around (While avoiding eachother and other objects.) I also want to confine them in a certain radius around the town/village.

I only need to implement the Walking and Idle action for that stage. I will add the other ones later, but how should I go about programming this? I don’t want to use nodes (I’ve seen Mmph!'s Tutorial on AI without python).

So please give me some feedback on how I could do this, thanks!

by nodes, you mean like nodes from UE and junk? I don’t really think there is another way. Nodes define points, and they help command the object to it’s next action and position. I’d just use empties, or maybe planes with textures

I would just used defined points as Variables and have a property so it will only set these variables once (to cut down on logic) room1 = [1, 1, 0] room2 = [2, 5, 0] and just have a list of places.
then use the

def set_loc(place):
    pos = own.getCurrentPosition
    set_pos = #get a way to track to the position with python then when you want to track to it use

you could add a ray on the +y axis and if that is positive add a rotation actuator that will rotate it 45 or 90 degrees. use these for help

I am working on some AI at the moment, right now I’m actually creating the movement part of it.

How I am doing it is I assigned a property to the object called aiData, set to string with [0,0,0] in it, these are tri-ordinates(?) of where to move the object to.

I created an if condition so if the object is not within x blender units of this then to move towards it using a motion actuator, I did it like this:

if own.getPosition() == [aiData[0], aiData[1], aiData[2]]:
    speed = .05
    A = own.getPosition()
    B = [aiData[0],aiData[1],aiData[2]]
    rate = []
    n = [A[0]-B[0], A[1]-B[1], A[2]-B[2]]
    dis = sqrt(n[0] ** 2 + n[1] ** 2 + n[2] ** 2)
    if dis < .2:
    for i in n:
    motion.setDLoc(rate[0], rate[1], rate[2], 0)
    GameLogic.addActiveActuator(motion, 1)

The setOrientation() method that it is calling changes the orientation of the object +/- 45 degrees then chooses a random distance of 5-20bu to travel, its done like this:

def setOrientation():
    a = degrees(acos(ownOri[0][0]))
    n = randint(-45,45)
    angle = radians(a + n)
    R = [
        [cos(angle),-sin(angle), 0],
        [sin(angle), cos(angle), 0],
        [0      ,0       , 1]
    hyp = randint(5,20)
    y = sin(angle + radians(90)) * hyp
    x = cos(angle + radians(90)) * hyp
    aiData[0] += x
    aiData[1] += y
    aiData[2] = 0

The codes not perfect and it doesn’t do path finding either but its one way to make random movement.

P.S. I used this line at the top of my code:
exec("aiData = " + own.aiData)
To convert the string to a list, then this at the end to convert it back:
own.aiData = aiData