# Make a trail inside the bge

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

• what errors you are getting ?, how are saving the position ? – Chebhou May 25 '15 at 15:57
• The trails are not shown at all. – user14219 May 25 '15 at 16:07
• position is cleared every logic tic, you are doing that with own["positions"] = [] – Chebhou May 25 '15 at 16:20
• I know. How to fix that ? – user14219 May 25 '15 at 16:26

## 1 Answer

positions variable is being cleared at every execution of the script by the line own["positions"] = [] to prevent this replace that line with :

if 'positions' not in own :
own["positions"] = []


Edit :
The position list was not extended properly it was taking pointers to the object position to fix this replace own["positions"].append(own.position) with own["positions"].append(own.position.copy())

• Thank you. But I have an other problem : I can't plot the trail, although the locations are putted in the 'positions' list. – user14219 May 25 '15 at 16:48
• @user14219 see if this will work – Chebhou May 25 '15 at 17:15