# how do I create a moving type of block like in Mario[box2d]

I want to create a block which only moves up and only when hit from below. I am trying out a distance joint and I read it can be used as a spring, is this the correct solution?

the way I have tried it is to create a block, and right underneath it I created a body and created a distance joint between these 2, however I do not see any type of spring physics, the block just falls down and acts like a rope joint.

DistanceJointDef j = new DistanceJointDef();
j.type = JointType.DistanceJoint;
j.frequencyHz = 4f;
j.dampingRatio = .5f;
j.bodyA = body;
j.bodyB = body2;


my joint def.

edit: right now I am just using a pristmastic joint and so far it seems okay.

• What are you trying to create? Do you want one of those movable blocks from the newer games that will move by one block height and stay there? Or are we talking about classic blocks being bumped from below? – Mario May 16 '14 at 20:17
• classic, like I am playing mario and I hit 5 blocks and they all get destroyed, maybe one gives me a mushroom. So far I might have found a solution by using a prismatic joint, this way it only moves vertically and by a certain amount. – gallly May 16 '14 at 20:39

I tried it out in RUBE and the Prismatic joint works fine for me:

What you may not have realized is that you can set joint limits on the prismatic joint, which makes this a lot easier to set up.

You can tune this by playing with the mass of the block, and the linear damping. You might also want to set the coefficient of restitution to zero.

• thanks, rube looks awesome. This is basically what mine looks like but yeah I have to mess with the settings some more – gallly May 18 '14 at 17:20

I don't know Box2D specifically, but using a physics simulation for this effect would be overkill. They certainly didn't use any physics calculations in Mario. :)
I would do this by linearly interpolating between the normal position and moved position.