I'm pretty new to blender and I'm trying to move an agent (in this case, a cube) randomly in bge. This is what my code looks like at this point:
import bge
import random
from mathutils import Vector
def main():
cont = bge.logic.getCurrentController()
owner = cont.owner
function = cont.sensors["Always"]
width = bge.render.getWindowWidth()
height = bge.render.getWindowHeight()
def set_object_pos(width, height):
owner.localPosition.x = random.randint(-1*width, width)*0.007
owner.localPosition.y = random.randint(-1*height, height)*0.007
current_frame = 0
loopnumber = range(100)
loopnumberlist = []
for number in loopnumber:
loopnumberlist.append(number)
for number in loopnumberlist:
set_object_pos(width, height)
print (owner.localPosition.x, owner.localPosition.y)
current_frame += 1
number += 1
main()
I just randomly created a loop because it would only print out 1 location no matter for how long the simulation ran. The problem I'm running into at this point is that the script will print out random locations but only moves the agent the first time the loop is run....any way to get the cube to move every time the loop is run? Or, better, is there any way to just call this function every frame? I thought using the Always controller would help but it hasn't worked that well...
Thanks!