# obj.rayCast() not working as intended

In the game engine, I've got a function which uses rayCast in asteroids. It doesn't work as intended, as even with x-ray turned on, it often doesn't see through objects without the desired property:

def shoot(self):
for n in self.cont.triggers:
if n > -0.5:
if self.ammo == self.maxAmmo:
self.c.actuators["ShootSound"].stopSound()
self.c.actuators["ShootSound"].startSound()
self.laser.worldPosition = self.pos
self.laser.orientation = self.ang.to_track_quat("Y", "Z")
self.ammo = 0
target = self.obj.worldPosition + self.obj.worldOrientation * mathutils.Vector([0, 1, 0])
hitObj = self.obj.rayCast(target, self.obj, 300.0, "asteroid", 1, 0)[0]
if hitObj is not None:
hitObj["pyObj"].smash()
exp = explosion(0.2, self.obj.worldPosition, self.fxScene)
self.scene["explosions"].append(exp)


The problem is that often, even when cast through objects, it returns None. This happens more often when explosions get in the way of the rayCast (despite not having the property), so I moved them to another background scene to test. It's now more reliable, but still often returns None when it shouldn't.

Any ideas as to what's going on? I'd be eternally grateful.

• If I understand you right you assume x-ray is turned on. As is now your call to rayCast() has x-ray flag turned off (6th argument) -> rayCast(target, self.obj, 300.0, "asteroid", 1, 0) – Monster Mar 6 '18 at 5:23
• Thank you very much, turns out I'm an idiot and miscounted the argument number. – Cameron Fazakerley Mar 6 '18 at 13:29