0
当object1与object2发生碰撞时,我希望object2消失而不影响object1的位置或速度。 Object1是动态的,object2是静态的。所以它就像是一个奖励对象击中我的主要对象,奖励对象应该消失而不影响任何东西。两个物体碰撞,一个应该消失而不影响另一个的位置
这里是我的碰撞功能代码:
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
这并没有真正回答 –
这个问题是对象2正在消失,但它碰撞时碰撞object1是问题 –
如果在创建对象时应用object2.isSensor = true,将会非常有用。如果在碰撞检查过程中应用它,它可能会在检测到碰撞后才会生效,并且它已经影响了对象1 –