Throwing dynamic objects (SOLVED)

I am a little confused with Defold’s physics.

I am trying to create a catapult that throws some blocks.
Now, there is a kinematic bar and spawning dynamic block, laying on it.

I rotate the bar (via go.animate), trying to throw a block, but it does not work.

I expect, that during rotation, dynamic object gets some inertia to start flying. But it seems, that when rotation finished, block did not have any forces (except gravity).

There is a gif, to show it:

My question is:
Is it normal in defold? Or I do something wrong?

As a workaround, I send apply_force when getting collusion_point_response message. But I do not like result.

Defold uses box2d so most resources related to it would be helpful.

You should add an extra rectangle to your swing collision so that it’s more like a boot or L shape at the end with the tip pointing outward to act as a kind of catch. Try that first and see if it helps. Second test spheres/circles instead of rectangles to throw.

We use Box2d so this might help. I think the key problem is that box2d only does separation between the dynamics and kinematics, so it’s not a real transfer of kinetic energy. As you can see from the example in the link, the dynamic balls are separated from the kinematic, rather than bouncing off. In some instances they in fact do bounce off, I wonder if that has to do with a particularly “deep” penetration of bodies in that case.

Thanks for replays and ideas.

I found a couple good tutorials how to create a catapult in Box2d, but they are not suite for Defold. In those tutorials (here and here) we must use Revolt joint, and customize motor speed and so on. But as I found in the forum, Defold is not support them yet.

Yes, that’s unfortunately true. Feel free to add a feature request of what’s missing.

I managed to create a catapult with the following setup:

Everything except ground and joint are dynamic.

5 Likes

Wow! Great!

Unfortunately, I am at work, so cannot try to implement a dynamic arm, to test this approach. :smile:

Anyway, How does it suppose to activate? Applying a force to the right side of the arm?

2 Likes

Yes, I did like this:

msg.post("#collisionobject", "apply_force", { force = vmath.vector3(0, -100000, 0), position =  pos + vmath.vector3(100, 0, 0) })

But you should probably also take into account the rotation of the arm to always apply the force perpendicular to the arm.

2 Likes