setMKS and velocityThreshold workaround

  1. physics.setMKS( “velocityThreshold”, 0 )

seems not to do job, so here is workaround. NOT extensively  tested: basic tests only.

[lua]local function workaroundVelocityTreshold(obj, bounce)

    local stickySpeed = 10  – new minimum speed for sticky behaviour px /sec

    local change = false

    print( "start " )

    local vx, vy = obj:getLinearVelocity()

    if math.abs(vy) < 0.1 and obj.lastY ~= 0 then

        if math.abs(obj.lastY) > stickySpeed then

            change = true

            vy = - obj.lastY * bounce

        else

            obj.lastY = 0

        end

    end

    if math.abs(vx) < 0.1 and obj.lastX ~= 0 then

        if math.abs(obj.lastX) > stickySpeed then

            change = true

            vx = - obj.lastX * bounce

        else

            obj.lastX = 0

        end

    end

    if change then

        obj:setLinearVelocity( vx, vy )

        obj.lastX, obj.lastY = vx, vy

    end

    print( “end” )

end

local function onGlobalCollision( event )

    if event.phase == “began” then

        local obj, b = event.object2, event.contact.bounce

        obj.lastX, obj.lastY = obj:getLinearVelocity()

        print( “GC-”…obj.lastX…", "…obj.lastY )

        

        local wrap = function() workaroundVelocityTreshold(obj, B) end

        timer.performWithDelay( 0, wrap )

    end

end

Runtime:addEventListener( “collision”, onGlobalCollision )

– dont forget to remove it latter

Runtime:removeEventListener( “collision”, onGlobalCollision )

[/lua]