How to use joints?

Discuss issues specific the Javascript port of Box2D
Posts: 2
Joined: Sat Dec 06, 2014 10:00 am

How to use joints?

Postby SchoolScience » Sat Dec 06, 2014 10:05 am

I've tried to use the documentation and I've used many tutorials and I can't get two bodies to generate a joint between them. Here is my code:

var swordWeld = new b2DistanceJointDef();

swordWeld.bodyA = this.shape.body;
swordWeld.bodyB = this.sword;
swordWeld.length = 5;
swordWeld.localAnchorA = this.shape.body.GetWorldCenter();
swordWeld.localAnchorB = this.sword.GetWorldCenter();
var joint = world.CreateJoint(swordWeld);

I've also tried the following:

swordWeld.Initialize(this.shape.body, this.sword, this.shape.body.GetWorldCenter());

Why won't the joint appear?

EDIT: I've gotten the joint to appear for one second after loading, then it vanishes...
Last edited by SchoolScience on Sat Dec 20, 2014 11:19 pm, edited 1 time in total.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo

Re: How to use joints?

Postby irresistible force » Mon Dec 08, 2014 4:22 am

What do you mean by 'appear'? This code will not draw anything for you. If you are using the debug draw, remember to enable the flag to draw joints.
Is this Javascript? What port? Does that port actually have weld joints implemented?

Posts: 2
Joined: Sat Dec 06, 2014 10:00 am

Re: How to use joints?

Postby SchoolScience » Wed Dec 10, 2014 9:55 am

Okay, I've enabled joints to be drawn using debug draw. The problem still persists: The two objects are not being welded together. Yes, I'm using Javascript and the latest port of Box2DWeb. According to the documentation, it supports joints.

Return to “Javascript”

Who is online

Users browsing this forum: No registered users and 2 guests