Here is my code:

import bge
from bge import logic

controllor = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()

target = scene.objects['Target']
ray = controllor.sensors['Ray']

if (ray.hitObject and not 'Fire_False' in ray.hitObject):
    target.worldPosition = ray.hitPosition

I've noticed that if you have an object with the prop "Fire_False" and an object behind it without the prop, the ray doesn't track to the object behind the first. I am looking to modify this script so the ray can look through the object with the prop and find other objects behind it. If the script sees a situation like this, it uses the object with the prop as a dead end, and does not continue tracking. How can I have this ray see though props? Any help is appreciated. Thanks!

EDIT: I would also like this to work if an object in in another object and the bound object does have Fire_False, but the object in it doesn't.


1 Answer 1


You are thinking of this backwards from how the ray sensor works. You want to look for "target" no mater what is in front of it.

Add a property to everything you want to get hit say "target". Then change the ray senor to look only for that property ("target") and enable X-Ray Mode.
Ray sensor

Last your code can then look like this.

if ray.hitObject:
    target.worldPosition = ray.hitPosition

X-Ray Mode will let the ray look through everything, and the property will only return the objects with the property "target."

  • $\begingroup$ I'm sorry if I was unclear on this. I need the ray to detect objects without the property Fire_False. The ray and script is in the camera. An empty is named "target" and that empty tracks to where the ray stops. When I use x-ray, the ray uses the last used position. $\endgroup$
    – blackhole
    Commented Jun 29, 2015 at 5:53
  • $\begingroup$ @blackhole I understood that from your question. You are still going to have to change the ray sensor look for a property (call it whatever you want I used "target") on all objects that you want to get hit. There is no way to use X-Ray Mode and script it to look only for objects that do not have "Fire_False." $\endgroup$
    – David
    Commented Jun 29, 2015 at 13:42
  • $\begingroup$ @blackhole i'm assuming you're using this so you can't shoot your allies and stuff. What david is saying is correct, you want to put a property on all of the badguys that means that you can shoot. or you may have the guns default always shoot and the allies in the crosshairs means you can't. it depends on the situation. $\endgroup$
    – ruckus
    Commented Jun 29, 2015 at 14:16
  • $\begingroup$ @Radish of the Opera You can shoot the good guys, that is not a part of this. I need an empty that is always at the center of the screen that collides with objects without the prop Fire_False. The objects with Fire_False are objects that trigger events and are invisible, or are not a part of the game. I already have tons of work put into this after I figured out what to do, and changing everything would be difficult. I am just looking for an x-ray to work. $\endgroup$
    – blackhole
    Commented Jun 29, 2015 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .