This extension will only work with Stencyl 3.1 or newer (build >= 7261).
The pulley joint block needs Stencyl 3.2 or newer (build >= 7754).Joints Extension
This extension should work on every platform. I have only tested it on Flash, if you any issues with it let me know.
This extension provides blocks to create and destroy joints, and to modify their parameters.
To see what you can do with it, check out this Demo
and the Ragdoll Test
. You can also find them on StencylForge as "Joints Sandbox" and "Ragdoll Test 3x".
There are currently blocks for all joints (that are implemented in the haxe port of Box2D) except for gear joints and friction joints.
To learn more about Box2D joints in general, take a look at the Box2D manual (PDF)
.Download this Extension
. (For instructions see How to Install and Update an Extension
When a joint block expects coordinates for an anchor point of an actor, the coordinates are relative to their origin point of the actor (by default the center of the actor). If you want to attach a joint to the center of an actor, use ( x: 0, y: 0 ).
The blocks that only expect coordinates for one anchor point, calculate the coordinates of the second anchor point based on the position of the actors.
Use the blocks only for the type of joint that they are meant for. If you use a block on the wrong type of joint, you will get an error, like "Type Coercion failed: cannot convert box2D.dynamics.joints::B2RevoluteJoint@f1eae359 to box2D.dynamics.joints.B2DistanceJoint".
To specify the axis for line joints and prismatic joints, enter the coordinates of vector pointing in the desired direction, and make sure that the length of the vector is shorter than or equal to 1. For example, to create a line joint that restricts an actor to horizontal motion, you would enter ( x: 1 y: 0 ). For a 45° diagonal, you can enter ( x: sqrt(2)/2 y: sqrt(2)/2 ), which has length 1, or for example ( x: 0.5 y: 0.5 ), which is shorter than 1.
Most values of a newly created joint are 0 (or false) by default. This means that, for example, to turn on a motor, you need to enable the motor, set the maximum force and set the motor speed. Otherwise it will do nothing.
There is also a block to return the last created joint, a joint selected from the scene, or a joint attribute. Normally you won't need to use this block, as you get the same dropdown for the joint fields in the other blocks and attributes, but sometimes it can be useful, for example, for storing joints in a list.Mouse Joints
Mouse joints are useful to drag actors in a game with physics, since the mouse joint will drag the actor towards the mouse and thus works well with collisions (unlike setting actor coordinates directly). Usually you will want to set the target of the mouse joint to the current mouse coordinates in every frame. Make sure to set the maximum force (1000 * mass of the actor is a good starting point), otherwise the mouse joint won't have an effect. Distance Joints
A distance joint fixes the distance between two actors, or one actor and a point on the scene.
* Stick joints created in the scene editor are distance joints internally.Line Joints
A line joint restricts the motion of the actor to a given axis. Rotation is still allowed.
* Slide joints created in the scene editor are line joints internally.Prismatic Joints
Like a line joint, a prismatic joint restricts the motion of the actor to a given axis, but rotation is also restricted.Revolute Joints
A revolute joint constrains two bodies to share a common point while they are free to rotate about that point.
There are four different blocks to create a revolute joint, to connect two actors, or to attach an actor to the scene, and with one anchor point (the other one calculated automatically) or two anchor points, respectively.
* Hinge joints created in the scene editor are revolute joints internally. Weld Joints
A weld joint glues two actors together, or glues one actor to the scene. This can be useful for creating an object made out of multiple pieces that can fall apart (when you destroy the weld joints that held the pieces together).Pulley Joints
A pulley joints connects two actors with a rope and a pulley (or two) defined by the anchor points.Version History
1.0: Initial version, with blocks for mouse joints and revolute joints
1.1: Updated to use joint attributes
1.2: Added blocks for distance, line, prismatic and weld joints
1.3: Fixed set/get length of distance joints not accounting for physics scale
1.4: Added blocks for pulley joints