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 = self.fxScene.addObject("laserbeam", None, 10) 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) 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.