I've tried do to draw a curve with the bge module, assuming I have a list of locations :
for i in range(1, len(positions) - 1):
bge.render.drawLine(positions[i - 1], positions[i], (1, 0, 0))
But the following doesn't work at all. What is wrong with this ? This is the piece of code I've written, and I'd like to be able to draw the trajectory of the object.
import bge
own = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()
own["positions"] = []
own.applyForce((1, 1, 1), 0)
own["positions"].append(own.worldPosition)
for i in range(1, len(own["positions"]) - 1):
bge.render.drawLine(own["positions"][i - 1], own["positions"][i], (1, 0, 0))
EDIT:
Changed the script according to Chebhou's answer:
import bge
own = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()
if "positions" not in own :
own["positions"] = []
own.applyForce((1, 1, 1), 0)
own["positions"].append(own.worldPosition.copy())
for i in range(1, len(own["positions"]) - 1):
bge.render.drawLine(own["positions"][i - 1], own["positions"][i], (1, 0, 0))
own["positions"] = []
$\endgroup$