I have been having this problem for some time now, and I don’t know what is causing it. Basically, a script is called once by a Tap Always sensor, this appends a function to the pre_draw, therefore making it run every frame. See https://blenderartists.org/forum/showthread.php?438044-ccd-projectile-motion-manager
Anyway, what happens is that the script that should run every frame only runs once per bullet. Here is the script itself:
from bge import logic, render
scene = logic.getCurrentScene()
cont = logic.getCurrentController()
def main():
own = cont.owner
own["Bullets"] = {}
scene.pre_draw.append(BulletSystem)
#this runs once
def BulletSystem():
#this runs every frame
manager = cont.owner
manager["debugList"] = str(manager["Bullets"])
print(manager["debugList"])
keys = []
for key in manager["Bullets"]:
bullet = manager["Bullets"][key]
if not bullet.invalid:
start = bullet.worldPosition
end = start + (bullet.worldLinearVelocity * 0.05)
print("Start:", start, "End:", end)
hitObj, _ , _ = bullet.rayCast(end,start,0,"",0,0,0)
render.drawLine(start, end, [1, 0, 0])
if hitObj:
print("I hit" + hitObj.name)
if hitObj.children:
for child in hitObj.children:
if "turret" in child:
child["destroyed"] = True
scene.addObject("DustGen", bullet, 10.0)
bullet.endObject()
else:
keys.append(key)
else:
keys.append(key)
for keyz in keys:
del manager["Bullets"][keyz]
The important part is that the BulletSystem() runs every frame. So then why does the for loop not?