You can’t change the physical properties of an object during a collision, but set a timer for 1 millisecond and you can make it near enough. Here’s my function for modifying physical properties which can only be set at addBody() time:
[lua] – group is the dsiplay group/object to have a body applied to it
– you can pretty much ignore the warning if you call this func before adding a body to the group
function applyBody( group, params )
local isActive, vx, vy, rot = true, 0, 0, 0
if (group.getLinearVelocity) then
isActive, vx, vy, rot = group.isBodyActive, group:getLinearVelocity(), group.angularVelocity
end
physics.removeBody( group )
– the values here are from my code and are my defaults…
physics.addBody( group, {
bounce=params.bounce or .8,
friction=params.friction or 0,
density=params.density or .1,
radius=params.radius or 38,
filter=params.filter or {groupIndex=params.groupIndex or groupIndex}
} )
group.isBodyActive = params.isActive or isActive
group:setLinearVelocity( params.linearVelocityX or vx, params.linearVelocityY or vy )
group.angularVelocity = params.angularVelocity or rot
end[/lua]
Then call the function by passing in the names and values you want to set:
[lua] applyBody( someObj, { bounce=.1, linearDamping=2, angularDamping=8 } )[/lua] [import]uid: 8271 topic_id: 33454 reply_id: 132917[/import]