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.
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.