Laser Pointer for guns, barriers etc.

It’s pay back time, i just made this for other to use.
the laser always faces the camera like a billboard but the difference is a billboard only faces 2 directions, camera and the z axis. this laser points to another object or location but always faces the camera.
try it so you can understand better, i’m not good in explaining
works with all types of shader (single-texture to GLSL)
just import the pointer and laser to your scene and it’s ready to go.
you can change the code depending on what you are going to use it for.
credits are in the top of the script.
thank you. :slight_smile:



Laser.blend (516 KB)

Looking nice but you forgot to pack the textures!

sorry about that, ok i think it’s fixed now. :slight_smile:

Thank you!
This works perfectly!

Thanks, works great!
I’ll be using this in my project shortly, so convenient :slight_smile:


I was having some problems toggling the laser, so I modified your script a bit.

#Laser script made by: Roo-el Gi
#inspired by TPS Walk Setup by Liam Richardson (AKA Captain Oblivion)
#part of this script was from his Template so credits to him
#MarcoIT helped in vector problems so thanks to him too :)
from bge import logic

def main():
    cont = logic.getCurrentController()
    pointer = cont.owner
    toggle = pointer['toggle']
    cam = logic.getCurrentScene().active_camera
    campos = cam.worldPosition
    ob = logic.getCurrentScene().objects
    laser = ob['Laser']
    vec = pointer.worldOrientation.col[2]
    vecx = pointer.getVectTo(cam)[1]
    laser.alignAxisToVect(vecx, 2, 1)
    laser.alignAxisToVect(vec, 0, 1)
    mesh = laser.meshes[0]
    vert1 = mesh.getVertex(0,0)
    vert2 = mesh.getVertex(0,3)
    start = pointer.worldPosition
    end = start + (vec * 100)
    hit = pointer.rayCast(end, start)
    if toggle == 1:
        if hit[0]:
          end = hit[1]
          dot = pointer.scene.addObject("LaserDot", laser,1)
          dot.position = end
          length = pointer.getDistanceTo(end)
          vert1.x = length
          vert2.x = length
          vert1.x = 100.0
          vert2.x = 100.0
        vert1.x = 0.0
        vert2.x = 0.0

Just add a bool property called toggle to the pointer :slight_smile:

Thank you!