def NightLightsEffect(car):
scene = bge.logic.getCurrentScene()
dani = scene.objects["Dani_Box"]
cam = scene.active_camera
timeIs = bge.logic.globalDict["time"]
onTheRoad = Vehicle.NearRoad(car) < 50
if ( 7 < timeIs < 18 ) or not onTheRoad:
return
if "car-nigh-lights" not in bge.logic.globalDict:
bge.logic.globalDict["car-nigh-lights"] = []
lights = bge.logic.globalDict["car-nigh-lights"]
while len(lights) < 2:
light = Reuse.Create("Area_Lamp")
light.scaling = [10,10,10]
light.blenderObject.data.energy = 1000
light.blenderObject.data.shape = "DISK"
lights.append(light)
light.position = Vehicle.RelativePoint(car, (0,-50*(len(lights)),10))
spawnPoint = Vehicle.RelativePoint(car, (0,-100,10))
lights = sorted(lights, key=lambda x: x.getDistanceTo(spawnPoint))
if lights[0].getDistanceTo(spawnPoint) > 50:
for light in lights:
tp = light.position.copy()
tp.z -= 10
if cam.pointInsideFrustum(tp) == cam.OUTSIDE \
and light.getDistanceTo(car) > 20:
light.position = spawnPoint
light.position.z += 50
topos = light.position.copy()
topos.z -= 200
ray = light.rayCast(topos)
if ray[1]:
light.position = ray[1]
light.position.z += 10
break