first of all… gamelogic is very outdated, use bge.logic instead.
second, what you do here is waiting for a sensor to get positive then you loop trough all scene objects and then you set the color of the object that has a property called Fade.
So how to fix this you ask?
You should cast a ray from the camera in the direction you are looking at, then when the ray gets positive, you check if the ray,hitObject has the property, then you set the color.
#edit
This should do, collision changed to a ray sensor
run this in module mode, always (true) - python(module) -> scriptname.fade_item_in_front_of_camera
def fade_item_in_front_of_camera(cont):
own = cont.owner
scene = own.scene
#camera ray sensor (change the name)
ray = cont.sensors['ray_sensor']
if ray.positive:
#grab the object hit by the ray
hit_obj = ray.hitObject
#a compare distance, set however you like
distance_check = 10
#get the current distance to the object
distance = own.getDistanceTo(hit_obj)
#check if distance is smaller then our check
if distance <= distance_check:
#check if the hit_obj has a property called Fade
if "Fade" in hit_obj:
#set alpha/color
hit_obj.color = [ 0.0, 0.0, 0.0, 0.0]
else:
#return alpha/color
hit_obj.color = [ 1.0, 1.0, 1.0, 1.0]
i would hardly call that a “fade” , more like swift change from opaque to full transparent.
true, its a toggle, nothing fades, i used the wrong naming there, my bad. But if you use an animation instead of changing the color then you can create a fade in/out, so haha i thought in advance ^^
It works but the else funktion that the trensparency go back to full color and alpah dont get ???
what distance did you set in the ray sensor itself? make it longer(double) then the distance the scripts checks.
And does the console give any errors? I did not test the code.