Joints
Joint types
ExtremePhysics supports multiple types of joints. The type of joint defines how the movement of the bodies is constrained.
Hinge joints

Hinge joints connect two anchor points, like a hinge. The bodies can still rotate.
Hinge joints can be created with ep_hingejoint_create.
Distance joints

Distance joints constrain the distance between two anchor points. Actually this type of joint doesn't do anything unless you're using springs or limits. Distance joints that don't use springs or limits take virtually no processing time, so don't worry about performance.
Distance joints can be created with ep_distancejoint_create.
Rail joints

Rail joints connect the anchor point of the first body to a rail on the second body. The bodies can still rotate, and translate along the rail.
Rail joints can be created with ep_railjoint_create.
Slider joints

Slider joints connect the anchor point of the first body to a rail on the second body. Slider joints are very similar to rail joints, the difference is that slider joints will also block the relative rotation of the bodies. The bodies can only slide along the rail, they can't rotate relative to each other.
Slider joints can be created with ep_sliderjoint_create.
Local coordinates
Joints use local coordinates to define the position of the anchor points. The following illustration shows how local coordinates work:

Motors
Motors try to change the velocity of the bodies connected by the joint. The motor will try to make the bodies rotate or translate with a fixed velocity.
Hint
Depending on the weight of the bodies, you might have to set the motor force to a very high value (e.g. 100000) to make it work. You can avoid this by using a lower density for your shapes (but it's not required).
Joint limits
Joint limits are used to add additional constraints to a joint. Joints can have a lower and an upper limit. Both limits can also be set to the same value to simply block all movement.

Springs
Springs are very similar to limits, but instead of blocking the bodies springs will apply a force to push the bodies back, just like real springs. Joints can have a lower and an upper spring. Springs use very little processing time (compared to motors and limits).
Special usages
Joints can also be used to simulate some special things you might not think about immediately.
Joint friction
You can use joint motors to simulate friction. Just set the motor velocity to zero and set the motor force to a relatively low value. The motor will try to stop the body whenever it moves, but since the motor force is too low it will yield easily.
Servo
A servo is a mechanism similar to a motor, but instead of controlling the velocity of the motor it controls the position directly. You can do something similar in ExtremePhysics with joint limits and limit velocities. This example uses a hinge joint, but the same method can be used with any type of joint.
// create event servo_angle = degtorad(30); servo_maxvelocity = degtorad(3); servo_maxtorque = 100000; // step event var current_angle, velocity; current_angle = ep_hingejoint_get_rotation(global.world, joint); velocity = max(-servo_maxvelocity, min(servo_maxvelocity, servo_angle-current_angle)); ep_hingejoint_set_lower_limit(global.world, joint, servo_maxtorque, current_angle+velocity, 0, velocity); ep_hingejoint_set_upper_limit(global.world, joint, servo_maxtorque, current_angle+velocity, 0, velocity); // changing the position of the servo servo_angle = degtorad(60);
The limit velocity is needed because ExtremePhysics uses the velocity of the object to simulate collisions with other objects. Without the correct limit velocity the collisions wouldn't be realistic at all.
You can also use the joint motor instead of the joint limits, but it's not recommended. Motors can only control the velocity, not the position. It works, but the result isn't as good.
Comments
Luke |
Comment #1: Sun, 17 Apr 2011, 0:20 (GMT+1, DST) what kind of things do you mean by special usage? |
Dreadofmondays |
Comment #2: Mon, 27 Jun 2011, 16:21 (GMT+1, DST) I love this engine, it's been really useful so far. I was hoping I wouldn't have to do this, but I can't think of another way, so I'm going to make a request to you, Mr Maarten. The request is: Can you please add a way to anchor objects together? That is, make one move as if it was stuck to the other, rotation and all. This is important if the objects are separated from each other, as in my case. I've tried to fake it with hinge/slider joints and limits, but it doesn't work if the objects aren't on top of each other. If you have a way to do this using what's already here, please tell me! :D Otherwise, you may have to implement it. ^_^ |
Maarten BaertAdministrator |
Comment #3: Tue, 2 Aug 2011, 2:31 (GMT+1, DST) Quote: Luke
what kind of things do you mean by special usage? I mean joint friction and servos :). Those are actually 'sub-headers', but the font isn't very clear (I think I will add numbers to the headers when my new BBcode parser is finished). Quote: Dreadofmondays
I love this engine, it's been really useful so far. I was hoping I wouldn't have to do this, but I can't think of another way, so I'm going to make a request to you, Mr Maarten. The request is: Can you please add a way to anchor objects together? That is, make one move as if it was stuck to the other, rotation and all. This is important if the objects are separated from each other, as in my case. I've tried to fake it with hinge/slider joints and limits, but it doesn't work if the objects aren't on top of each other. If you have a way to do this using what's already here, please tell me! :D Otherwise, you may have to implement it. ^_^ I could add 'weld joints', but it would essentially be the same as a hinge joint with limits. It just can't get much better. It might be a bit faster, but it's still not perfect (unlike using just one body with multiple shapes). If hinge joints with limits don't work properly for some reason, that's caused by either a bug, or bad/incorrect settings. Could you give me some more information about how you create these hinge joints, and also the world settings you're using? PS: You don't have to copy your comments to get them noticed, I use the 'Recent comments' button to find new comments :). Last modified: Tue, 2 Aug 2011, 2:34 (GMT+1, DST) |
Solarboy |
Comment #4: Tue, 27 Dec 2011, 10:24 (GMT+1, DST) Hello again! I have a question about hinge joints. How would one get the x and y of a hingejoints anchor points? Similar to how there is ep_body_get_x and ep_body_get_y for bodies, is there someway to do the equivalent for hingejoints? I haven't seen anything like this in the reference section, nor can I think of another way to obtain this information without causing other problems. Thanks for your time, and keep up the good work! |
Maarten BaertAdministrator |
Comment #5: Wed, 28 Dec 2011, 21:34 (GMT+1, DST) Quote: Solarboy
Hello again! I have a question about hinge joints. How would one get the x and y of a hingejoints anchor points? Similar to how there is ep_body_get_x and ep_body_get_y for bodies, is there someway to do the equivalent for hingejoints? I haven't seen anything like this in the reference section, nor can I think of another way to obtain this information without causing other problems. Thanks for your time, and keep up the good work! Assuming you still know the local coordinates of the anchor points, you can use ep_body_coord_world_to_local_x/_y on one of the bodies. |
Elfdud7 |
Comment #6: Tue, 24 Apr 2012, 2:44 (GMT+1, DST) Is there any way to make an elastic rope with distance joints? I Seem to have gotten it pretty well; here's the generation code: line[n]=ep_distancejoint_create(global.world,me[n],me[n-1],0,0,0,0) Last modified: Tue, 24 Apr 2012, 3:11 (GMT+1, DST) |
Maarten BaertAdministrator |
Comment #7: Thu, 26 Apr 2012, 0:25 (GMT+1, DST) Quote: Elfdud7
Is there any way to make an elastic rope with distance joints? I Seem to have gotten it pretty well; here's the generation code: line[n]=ep_distancejoint_create(global.world,me[n],me[n-1],0,0,0,0) Increase the maximum limit force, e.g.: ep_distancejoint_set_upper_limit(global.world,line[n],1000000,dis/20,1,0) |
Elfdud7 |
Comment #8: Sat, 12 May 2012, 10:48 (GMT+1, DST) Hey, Thanks! It didn't work perfectly, but the joints effected by what you suggested seemed to work excelently. I gave up, replaced with a new system. Is there any way to connect two equally sized blocks with a linear "spring" which allows linear movement in one direction, but without rotation? |