Hey! I am happy to say I am working on a laser and it works pretty sweet! So here goes!
This laser is a ‘cylinder’ object that extends along the y axis, assuming it is rotated so that the ‘length’ goes along the y axis (which I have decided I want to be forward in my case, you could make it x or z depending on what you want)
The important thing about this cylindar is WHERE the ORIGIN is! Snap the cursor to one ‘end plane’ of the cylindar, apply the origin there. If the origin is in the middle, the laser will shoot out ‘in either direction’ or ‘grow from the center’. If you set the origin from one end (towards the -y axis) it will extend toward the y axis!
So! This laser looks for a ‘player’, finds the distance to the player, and then scales itself to the distance between its origin and the player, add peeeewww effects! As long as this object gets loaded in ‘to scale’, as in, isn’t scaled to .25 or whatever, it will work perfectly! So! Here is the code ! YAYAAAA!
from bge import logic, renderfrom mathutils import Vector
cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
obj = scene.objects
delay = cont.sensors['Delay']
for i in obj:
if 'Player' in i: # --- this says, if the property Player is in an object in the scene
vectToPlayer = Vector(own.getVectTo(i)[1]) # --- gets a vector to the player
vectToPlayer.magnitude = .5 # ---- assigns a speed for the vector (I'm pretty sure it will scale at this speed)
own.alignAxisToVect(vectToPlayer, 1, 2) # ---- aligns its y axis (its forward, head pointy axis, to the player)
distancetoplayer = own.getDistanceTo(i) # ---- gets the distance to the player
own.scaling = (1,distancetoplayer,1) # ---- scales itself 'to' the player, assuming the origin correctly set
if delay.positive: # ---- delay
own.endObject() # ---- ends the laser
I like retro effects, so I am probably going to leave it as a simple object, shadeless, but if you want it to be fancier, do things like:
1.Change material properties, animate the ‘object color alpha’ to make the laser ‘fade out’
2. When the laser is added, cause a ‘stand by’ light’s energy to increase to create a flash and illuminate the area, as I learned from a Solar Lune video
3. Add 10 simple polygons that look like little doodads that add along with the laser and fly off like plasma juice or something
4. etc