How to make a 2D Jack in the Box - Struggling with SpringConstraints

I’m attempting to make something that resembles a Jack in the Box. I thought this would be simple but after a few days of struggling to figure this out I am now hoping the community can help me out…

What I’m trying to make looks something like this:

The red part serves as the “Base”, while the blue part serves as the “Jack”. At rest, the Jack is directly above the Base, and should always return to this position. As the Base moves, the Jack can wobble back and forth, but only along the XY plane.

I figured out that I can keep the Jack in the XY plane using a PlaneConstraint. My issue is I cannot figure out how to keep the spring upright. I thought if I made the spring very stiff, I would get the desired behavior. However the spring keeps “falling” - the constraint between the Base and the Jack holds, but the base of the spring is not locked into place and ends up rotating where the Jack ends up next to the base.

I need to align the orientation of the spring constraint somehow… I’ve tried to AlignOrientation and PrismaticConstraint in addition to the spring on the same attachments but I still get the “falling” result:
falling

Ideal behavior would look something like this when the base moves, where after a short amount of time the Jack would wobble right and left and return to the upright position:

Any help is appreciated, thanks in advance!

1 Like

Use an AlignPosition, just make the forces in it fairly weak.
Classes/AlignPosition
align-position
Position the Attachment of the red box at the spot you want the blue box to sit and have the blue box Attachment Position at 0,0,0
Put the Spring Attachment in the blue block 1-2 studs below the bottom surface of the blue block so it pulls that face closest to the red block. If you attach it to the center the blue box will just spin around.

I just tried AlignPosition and the blue blox is still falling over… the constraints also may be affected when I try to move the base, maybe I need to move the base via script? I’m moving it on the server so the Network Ownership remains on the server… I’ve played around with this for so long I always feel like I’m taking one step forward and two steps back, could I bother you to help fix my model that’s attached?

This is with AlignPosition with RigidityEnabled so I’m not even sure why it can drop…

jackbox.rbxm (6.6 KB)

Ah I figure it out (almost). The AlignPosition needed to be between the Jack attachment and a new attachment above the Base aligned with the Jack attachment to ensure those positions are aligned…

Here is the model in case anyone else reading this may be curious:
jackboxWorkingButRotating.rbxm (6.3 KB)

Only issue now as you can see in the video is the Jack is spinning around the Z axis. Possibly needs an AlignOrientation, I’ll play around with this but feel like the hard part is solved. I’m not going to mark the post solved until the rotation issue is solved though, so anyone feel free to weigh in.

Thanks Scottifly

I took a look at your model and found you had an AlignPlane in it which keeps it rigid in only one plane. That means jack only pivoted one way.
I took it out and added an AlignOrientation instead to keep jack aligned with the box.
After tweaking some of the Forces, Spring Attachment Positions, and the AlignPosition Attachments. I found that if they were centered on jack it’d rotate oddly so I moved them up so it’d ‘bob’ more realistically like the spring was pulling it.

Have fun with it. Experiment with the forces and Attachment Positions to make it move the way you’d like.
JackBoxSpringAlignPosOrient.rbxm (6.7 KB)

thanks Scottifly! the tweaks you made really helped achieve the ‘bob’ feel I was looking for. The PlaneConstraint was actually intentional - while I’m using a Jack in the Box as a relatable reference, the intended use for this was something that should only move along a plane (see my original description, mentioned XY plane and is why the title is 2D Jack in the Box).

But the ‘bob’ tweaks make a huge difference - I’m using your model and added back the PlaneConstraint to get the best of both worlds. Thanks so much for your help, really appreciate it.

1 Like

@Scottifly - sorry to bother one last time, but I’ve been trying to preserve the AlignOrientation “bob” behavior in the Z axis while preventing any rotation in the X and Y axis. In other words if the camera is pointing at the Jack and Base as I’ve drawn them in the pictures above, I want the face of the Jack pointing at the camera to always be pointing at the camera; the Jack can bob / turn left and right but not turn in any other direction.

The AlignOrientation you added uses AlignType AllAxis, and I’ve determined that this Z axis rotation is the PrimaryAxisParallel axis. So then I thought I could create 2 other AlignOrientations, each using one of the other 2 axes with RigidityEnabled true, but this is causing some funky behavior… I’ve also tried a hinge constraint to limit the movement to only the Z axis but this is ruining the springy bob effect…

Keep this behavior (bobs initially after rotation):

Remove this behavior:


Replace this this behavior (Jack always facing the camera):


I could force this behavior using a script but wanted to pick your brain on if this was possible.

I’m not sure.
I know if you remove the ‘ReactionTorqueEnabled’ it’ll allow the jack to rotate, but as far as making the rotation face the camera I have no clue.

Ok no worries - I’m only rotating the Base around the Z axis and was seeing that the Jack was sometimes rotating in different axes if there the rotation was rapid / changing. But seems like increasing the forces for the AlignOrientation fixes this unintended behavior and keeps the Jack in the right direction.

1 Like

Can you share you final tweak to the model he gave you?

Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.