Problem with rayCastTo() and IF

hi. i’m using this code:


Hit = scene.objects["CameraBoundary"]
Flare = Sun.rayCastTo(Hit,350,"Player")

if Flare == "Default":
    Sun["Flare"] = True
else:
    Sun["Flare"] = False

Simply i want to cast a ray and if it hit object called Default it will set some property to TRUE and reverse.

This is working


Print(Sun.rayCastTo(Hit,350,"Player"))

but i’m stuck in the IF function now :confused:

thanks for help :smiley:

Hi ChäeMil,

rayCastTo() returns a reference to an KX_GAmeObject not a string. A string will never equal a KX_GameObject. But the name of the KX_GameObject does:


Hit = scene.objects["CameraBoundary"]
Flare = Sun.rayCastTo(Hit,350,"Player")

Sun["Flare"] = (Flare is not None and Flare.name== "Default")

If you give your “Default” a unique property “Default” you do not even need to check the name. BTW. This looks like a perfect situation for a ray sensor (checking for an object with a specific property).

Thanks Monster! This solved it. And here’s little demo of it :wink: