Laser Beam Logic and Python (ray based - scales a plane or ?)

Note the object on layer 2 “Laser” you can add a alpha plane, or a different shape if you choose,


import bge



def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    sens = cont.sensors['Keyboard']
    sens2 = cont.sensors['Ray']
    


    if sens.positive:
        Dist=50
        
        if sens2.hitObject:
            hitPos=own.worldPosition.copy()
            hitPos.x=sens2.hitPosition[0]
            hitPos.y=sens2.hitPosition[1]
            hitPos.z=sens2.hitPosition[2]
            diff=own.worldPosition-hitPos
            Dist=diff.magnitude
        ## removed indent below
        scene=bge.logic.getCurrentScene()
        Laser=scene.addObject('Laser',own,1)
        Laser.applyMovement((0,1,0),1)
        Laser.localScale=(1,Dist,1)
            
     


main()



Attachments

Laser.blend (443 KB)