If you run the code below as per the raycasting example it all works fine:
local physics = require( "physics" ) physics.start() local ground = display.newImage( "ground.png" ) ground.x = 160 ground.y = 445 physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } ) local crate1 = display.newImage( "crate.png" ) crate1.x = 120 crate1.y = 0 physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } ) local crate2 = display.newImage( "crate.png" ) crate2.x = 200 crate2.y = 120 physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } ) local ray = nil local from\_x = 0 local from\_y = 0 local to\_x = 320 local to\_y = 500 local unbroken\_line = display.newLine( from\_x, from\_y, to\_x, to\_y ) unbroken\_line.width = 2 unbroken\_line:setColor( 255, 0, 0 ) local gameloop = function(event) if ray then display.remove( ray ) end local hits = physics.rayCast( from\_x, from\_y, to\_x, to\_y, 3 ) if hits then print( "Hit count: ", #hits ) for i,v in ipairs(hits) do local object\_name if v.object == ground then object\_name = "ground" elseif v.object == crate1 then object\_name = "crate1" elseif v.object == crate2 then object\_name = "crate2" else object\_name = "unknown" end print( "Hit: ", i, object\_name, v.x, v.y) end ray = display.newLine( from\_x, from\_y, hits[1].x, hits[1].y ) else ray = display.newLine( from\_x, from\_y, to\_x, to\_y ) end ray.width = 2 end Runtime:addEventListener("enterFrame", gameloop)
However if you change either from_x or from_y to anything other than zero it doesn’t work.
If you change from_x from 0 to 1 you get some rather odd results.