Hi there.
So, i need to D&D static box2d objects, but dynamic objects shoud correctly react to that. For example, if i have dragable platform (static object) at the bottom of the screen and dynamic box above it, then when i move platform from bottom to top, box shoud gain impulse and bounce from platform when i drop platform.
I was trying to use mouse joint, but it didnt work.
Any other solutions?
Simple project attached (just in case)

And another quick question. How to correctly override Sprite methods setX, setY, setPosition and e.t.c.? Right now i have something like this:
function Box:setX2(x)
self:setX(x)
self._body_pos[1] = x
self.body:setPosition(x, self._body_pos[2])
end
function Box:setY2(y)
self:setY(y)
self._body_pos[2] = y
self.body:setPosition(self._body_pos[1], y)
end
function Box:setPosition2(x,y)
self:setPosition(x, y)
self._body_pos[1] = x
self._body_pos[2] = y
self.body:setPosition(x, y)
end |
Comments
In short, you can use setPosition method outside of the world:step method. This means, do not use it in box2d callbacks(PRESOLVE,POSTSOLVE,BEGIN_CONTACT etc).
Well, i think i can do it by using only dynamic bodies, but with 0 gravity. And for non dragable objects apply impulse/set angular velocity. Idk, need to try.
Anyway, i solved my problem
I'm just setting the linear velocity like:
Project attached.
Likes: antix