Trace

To do collision detection, we need tracing in scene. The trace class is for this purpose. For begin tracing, we need new a trace class and set it's shape, start position and end position; then use the scene.trace() function. After tracing, you can get stop position, collision plane, progress fraction, etc. The progress fraction = d1/(d1+d2), so it's value range is 0 - 1; if fraction<1, then blocked, else full progress. See the illustration above.

Example :

-- check whether empty in front of player

local movtar=player.getMovTar()
local t=trace.new()
t.pointed(movtar.isPoint())
t.setBoundingBox(movtar.getBoundingBox())
local vfront=camera.getFront()
vfront.y=0
vfront.normalize()
t.setStart(player.getPosition())
t.setEnd(t.getStart()+vfront*50)
scene.trace(t)
if (t.getFraction()>=1) then
    print('empty in front')    -- empty in front
else
    print('blocked in front') -- something blocked
end