Hi!
I’m playing around with the raycasting demo and I’m wondering how I should do if I want the beam to continue from where I touch to the end of the wall? For now the beam just go to the point where I touch, but I want it to continue (in the same direction) to the side of the screen. How should I tackle this problem? Do I have to do some trigonometric calculations for this or is there a simpler way?
http://www.coronalabs.com/blog/2013/05/07/physics-raycasting-and-reflection/
EDIT:
Solved it.
else local xDist = destX-startX local yDist = destY-startY local slope = yDist / xDist local angleBetween = math.deg( math.atan( yDist/xDist ) ) if ( startX \< destX ) then angleBetween = angleBetween+90 else angleBetween = angleBetween-90 end local wallY local wallX if angleBetween \> -60 and angleBetween \< 60 then wallY = 0 wallX = ((wallY - destY) / slope) + destX elseif angleBetween \> 60 and angleBetween \< 120 then wallX = display.contentWidth wallY = slope\*(wallX - destX) + destY elseif angleBetween \> 120 and angleBetween \< 180 or angleBetween \> -180 and angleBetween \< -120 then wallY = display.contentHeight wallX = ((wallY - destY) / slope) + destX else wallX = 0 wallY = slope\*(wallX - destX) + destY end if ( beamGroup.numChildren \<= maxBeams ) then local fbeam1 = display.newLine( beamGroup, startX, startY, wallX, wallY ) fbeam1.width = 10 ; fbeam1:setColor( 255,50,40,100 ) ; fbeam1.blendMode = "add" local fbeam2 = display.newLine( beamGroup, startX, startY, wallX, wallY ) fbeam2.width = 6 ; fbeam2:setColor( 255,80,40,180 ) ; fbeam2.blendMode = "add" local fbeam3 = display.newLine( beamGroup, startX, startY, wallX, wallY ) fbeam3.width = 3 ; fbeam3:setColor( 255,80,40,255 ) ; fbeam3.blendMode = "add" end transition.to( beamGroup, { time=800, delay=400, alpha=0, onComplete=resetFire } ) end
Best regards,
joelwe