1)I'm using box2d with windfield and I'm trying to simulate particles(like elements). So when an element with a random velocity hits an obstacle I want it to bounce to another directions. I can think of setting it's velocity to the velocity of the object it hit, but how about if it hits a wall with zero velocity. Sometimes when it does that it just slides in one direction.
This is what I use to move it:
Code: Select all
function Element:update(dt)
--collider is windfield collider, works like box2d body I think
if self.collider:stay("enter") then
local collision_data = self.collider:getEnterCollisionData('Shape')
local element = collision_data.collider:getObject()
self:resetVelocity()
end
end
function Element:resetVelocity()
self.collider:
--(??) applyLinearImpulse
setLinearVelocity(
lume.randomchoice({-vel,vel}),
lume.randomchoice({-vel,vel})
)
end