3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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? \$\endgroup\$
    – Mario
    Commented May 16, 2014 at 20:17
  • \$\begingroup\$ 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. \$\endgroup\$
    – gallly
    Commented May 16, 2014 at 20:39

2 Answers 2

5
\$\begingroup\$

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

mario_block

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.

\$\endgroup\$
1
  • \$\begingroup\$ thanks, rube looks awesome. This is basically what mine looks like but yeah I have to mess with the settings some more \$\endgroup\$
    – gallly
    Commented May 18, 2014 at 17:20
-1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .