—
Okay, I found the files I needed. I had them saved in a weird spot. If I had lost all that work I would have deserved an award for worst file management ever.
If you have any trouble understanding my directions, let me know.
First, make sure you backup the physics behavior. You can edit it directly if you want but as noted above this presents certain risks. Either way you should make a backup of both the vanilla and edited versions.
If I recall, the prismatic joint can act wonky if you don't understand how it works so if you are not familiar with it you can check out box2d documentation on it. I kept the names of the parameters the same, so it should make sense.
In the edittime file you will want to add the following action beneath the others:
--------------------------------------------------------------------------------
//Limited Prismatic joint
AddAnyTypeParam("This image point", "Name or number of image point on this object to connect object to. Use 0 for the center of gravity and -1 for the object origin.");
AddObjectParam("Object", "The object to attach.");
AddNumberParam("Lower translation", "The lower limit of translation allowed, in pixels.");
AddNumberParam("Upper translation", "The upper limit of translation allowed, in pixels.");
AddNumberParam("Angle", "The angle to which translation will be constrained to, in degrees");
AddAction(28, af_none, "Create limited Prismatic joint", "Joints", "Create {my} limited Prismatic joint at image point {0} to {1}, limited from {2} to {3} pixels, at {4} degrees", "Connect another object to a point on this object and limit the range of movement along a particular Axis.", "CreateLimitedPrismaticJoint");
-----------------------------------------------------------------------------------------------------------------------------------------------------
In the runtime file, things are a little less straight forward than kinematics. you need to add the corresponding action: (make sure you add it in the right area, just to keep things tidy. Just scroll down till you find the other Acts.prototype.something.
----------------------------------------------------------------------------------------------------------------------------------------------------
// Added by Ruskul
// type 3, takes 5 params
Acts.prototype.CreateLimitedPrismaticJoint = function (imgpt, obj, lower, upper, angle)
{
if (!obj || !this.enabled)
return;
var otherinst = obj.getFirstPicked(this.inst);
if (!otherinst || otherinst == this.inst)
return;
if (!otherinst.extra.box2dbody)
return; // no physics behavior on other object
this.myCreatedJoints.push({type: 3, params:
});
this.doCreateLimitedPrismaticJoint(imgpt, otherinst.uid, lower, upper, angle);
};
behinstProto.doCreateLimitedPrismaticJoint = function (imgpt, otherinstuid, lower, upper, angle)
{
if (!this.enabled)
return;
var otherinst = this.runtime.getObjectByUID(otherinstuid);
if (!otherinst || otherinst == this.inst || !otherinst.extra.box2dbody)
return;
otherinst.extra.box2dbody.c2userdata.joiningMe.add(this.inst);
var myx = this.getInstImgPointX(imgpt);
var myy = this.getInstImgPointY(imgpt);
var jointDef = new b2PrismaticJointDef();
jointDef.Initialize(this.body, otherinst.extra.box2dbody, getTempVec2a(myx * worldScale, myy * worldScale), getTempVec2b(1,0));
jointDef.set_lowerTranslation(lower * worldScale);
jointDef.set_upperTranslation(upper * worldScale);
//if (lower <= 0 & upper >= 0) // make sure upper and lower don't exceed 0
jointDef.set_enableLimit(true);
this.myJoints.push(this.world.CreateJoint(jointDef));
};
// /End added by ruskul
----------------------------------------------------------------------------------------------------------------------------------------------------
Next , in the following function "behinstProto.recreateMyJoints = function()" add an additional case:
-----------------------------------------------------------------------------------------------------------------------------------------------------
// added for ruskuls additions
case 3:
this.doCreateLimitedPrismaticJoint(j.params[0], j.params[1], j.params[2], j.params[3], j.params[4]);
break;
-------------------------------------------------------------------------------------------------------------------------------------------------------
This should be in the switch statement right above default:.
Now, I didn't provide any expressions or the like for determining if this joint exists, but setting those up shouldn't be to hard. I never needed them so I didn't add them but if you find you do and need some help, let me know.
Also, there may be bugs. I'm not sure because I never use save game, but I imagine if you try to save the game, this might break. I never use the giant save everything feature in construct and only ever save specific variables to local storage so, again, this hasn't affected me. If this makes a bug for you, I'm pretty sure the fix is easy, and I can probably help you out there if you need it.
lastly, I named it limited prismatic joint because it goes hand in hand with the limited revolute joint. If there was no limit it could move along the chosen axis indefinitely. The limits simply specify how far it can go in a particular direction before stopping.
Hopefully this runs for you! Let me know if you get it working!
Cheers
-Ruskul