Beams

Blitz3D Forums/Blitz3D Beginners Area/Beams

I would try to
cyl=createcylinder()
fitmesh cyl,-1,0,-1,2,2,2
hideentity cyl
...
while (endofgame=0) and keydown(1)=0
 if mousehit(1)
  showentity cyl
  pointentity cyl,targetmesh
  scaleentity cyl,1,entitydistance(camera,targetmesh),1
 endif
 ...
wend


But there's a problem when there is no target mesh. So you first should do a camerapick. (Entitypickmode for all meshes must be set correctly). If there is a mesh behind the crosshair or so, you can use it as targetmesh. If there is nothing, you may position a dummy pivot at that location and use it as targetmesh.

Please note when you texturemap the cylinder, you may alter the ScaleTexture dynamicly to make it fit the beam lenght.

EDIT:

To limit the max beam range yoiu may use an invisible sphere that will give you the position for a dummy pivot if you didn't hit anything:

helperpivot=createpivot()
s=createsphere()
scaleentity s,100,100,100
flipmesh s
entitypickmode s,2
entityalpha s,0
entityparent s,camera
...
; then somewhere inside the mainloop, right before you point the beam to the target:
 pick=camerapick(camera,graphicwidth()/2,graphicsheight()/2)
 if pick=s ; didn't hit a real mesh
  positionentity helperpivot,pickedx(),pickedy(),pickedz(),1
  targetmesh = helperpivot
 endif