So I am trying to move an object to a list of points. For some reason, I just can’t figure out how to handle the lists. This example doesn’t work because the “listOfPoints” is constantly being re-updated to the original points, so popping doesn’t work.
import bge
cont = bge.logic.getCurrentController()
obj = cont.owner
motion = cont.actuators["Motion"]
listOfPoints = [1,5,8]
def moveTo(startingPosition, endingPosition):
dis = endingPosition - startingPosition
if dis < 0.05:
motion.dLoc = [0,0,0]
cont.activate(motion)
return 1
else:
motion.dLoc = [1,0,0]
cont.activate(motion)
position = obj.position
if moveTo(position[0],listOfPoints[0]):
print("yes")
listOfPoints.pop(0)
The same thing would happen if I tried to create an index variable and sort through the list.
import bge
cont = bge.logic.getCurrentController()
obj = cont.owner
motion = cont.actuators["Motion"]
listOfPoints = [1,5,8]
index = 0
def moveTo(startingPosition, endingPosition):
dis = endingPosition - startingPosition
if dis < 0.05:
motion.dLoc = [0,0,0]
cont.activate(motion)
return 1
else:
motion.dLoc = [1,0,0]
cont.activate(motion)
position = obj.position
if moveTo(position[0],listOfPoints[index]):
print("yes")
index = index + 1
The box moves to the first point just fine, I am just at a loss as to how to move on to the next point. Surely it can’t be that difficult? Can somebody help please?