0
$\begingroup$

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)[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.

$\endgroup$
  • 1
    $\begingroup$ 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) $\endgroup$ – Monster Mar 6 '18 at 5:23
  • $\begingroup$ Thank you very much, turns out I'm an idiot and miscounted the argument number. $\endgroup$ – Cameron Fazakerley Mar 6 '18 at 13:29
0
$\begingroup$

As is standard for my dyslexia, I misread the number of arguments. Don't make my mistake, kids. X-Ray was actually turned off.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.