两个物体碰撞,一个应该消失而不影响另一个的位置

Two objects collide, one should disappear without affecting the other's position

当object1 与object2 发生碰撞时,我希望object2 消失而不影响object1 的位置或速度。对象 1 是动态的,对象 2 是静态的。所以这就像一个奖励对象击中了我的主要对象并且奖励对象应该消失而不影响任何东西。

这是我的碰撞函数代码:

local function onCollision( self,event )
        --if my object hits a bonus object
        if(event.object2.name == "bonus")then
            --self:setLinearVelocity(0,horizontal)
            --I have tried the above method but every so often I receive an error
            event.object2:removeSelf()
            score = score*2
            scoreText.text = score --sets the new score
            Runtime:removeEventListener("enterFrame", event.object2)    
        else                
            composer.gotoScene( "restart"  )   
            Runtime:removeEventListener("touch", onObjectTouch)    
        end
    end

更新:

尝试将奖励对象设置为传感器,无论是在此区域中,还是在初始化它们时。

    event.object2.isSensor = true

    object2.isSensor = true

这应该允许对对象 2 进行物理和碰撞检测,而不会对其他对象产生任何影响。