Pedestrian AI

Hi all,

1.I’m trying to make pedestrians with AI for my game. What I have now it this filefollowerlike.blend (733 KB). The cube (pedestrian) is checking all the nodes in the list. Could you help me to add a line in the code to create some randomness. The idea is for the cube to pick random one of the nodes that is at a define distance from him. Please see the image. I want the cube to choose random from 1 2 3 witch are at an “x” distance from it.

  1. It is possible to do the list manually and still keep it in a loop?
    I’ve tried to do it but because of my poor knowledge in programming is not working.
    Help is appreciated.


1:
Without seeing your script, I can’t make it work for sure, but just try to adapt this to your own uses.


import random

nearbyNodes = []
bounds = 20 #nearby bounds

for x in nodeList:
    if player.getDistanceTo(x) < bounds:
        nearbyNodes.append(x)
nearNumber = len(nearbyNodes)
nodeToTrack = nearbyNodes[randInt(0,nearNumber)]

2:
Nope. But that’s okay, your loop happens almost instantly, so you can change your list and the next iteration should have updated information.

Why that complicated?

create an empty
create an action with a keyframe for each position to pick

pedestrian: setup an steering actuator to steer to this empty

Each time you want the pedestrian to change it’s mind (e.g. after reaching the empty) you let the empty play a random frame.

The demo in Prof. Monster’s BGE Guide to Character Setup uses a similar method.

MichelleSea, thanks but I can not integrate the code in my blend, is not working and my python skills are near to 0.

Thanks Monster for the option.