## Problem with Pivotjoints

Official forum for the Chipmunk2D Physics Library.
Bob
Posts: 3
Joined: Mon Jul 14, 2008 8:12 am
Contact:

### Problem with Pivotjoints

Hi guys,

first of all i like to thank you for this great library

now to my problem: I'm using a DLL version of Chipmunk i've created of the last version, and it works fine so far. Now im trying to connect 2 'wheels' (circle shapes) by a segment shape with a Pivot joint on each side and i just can't get it to work properly. As soon as one of the body coolides with something, the connection starts ro rotate like crazy. The program is written in Delphi, so i don't know if you can read anything out of the code, but i'll post it anyway.

Code: Select all

``````function CreateCircle(P: TCPVect; rad, mass, friction, elasticity: Single) : PCPBody;
var
body : PCPBody;
shape : PCPShape;
begin
body.p := P;
shape.e := elasticity;
shape.u := friction;
Result := body;
end;

function CreateConn(P1, P2: TCPVect): PCPBody;
var
shape : PCPShape;
begin
Result := cpBodyNew(0.0002, 0.0002);
P1 := cpBodyWorld2Local(Result, P1);
P2 := cpBodyWorld2Local(Result, P2);
shape := cpSegmentShapeNew(Result, P1, P2, 0);
shape^.e := 0;
shape^.u := 0;
shape^.layers := 0;
end;

function Test;
var
wheel1: PCPBody; {cpBody *wheel1 in c}
wheel2: PCPBody;
Conn: PCPBody;
joint: PCPJoint;
begin
wheel1 := CreateCircle(cpv(-20, 0), 10, 10, 1, 1);
wheel2 := CreateCircle(cpv(20, 0), 10, 10, 1, 1);
Conn := CreateConn(wheel1.p, wheel2.p);
joint := cpPivotJointNew(wheel1, conn, wheel1.p);
joint := cpPivotJointNew(wheel2, conn, wheel2.p);
end;
``````

i really don't have a clue on what i am doing wrong, so any hint would be highly appreciated.

regards, Bob
Bob
Posts: 3
Joined: Mon Jul 14, 2008 8:12 am
Contact:

### Re: Problem with Pivotjoints

Hi again,

i figured out, that i didn't nee a pivot, but a pinjoint. Using it, it seems to work, not quite the way i intended it, but thats hopefully gonna change too

im doing it like this

1. Create to wheels
2. Create a shape with layers set to 0 from wheel1.p to wheel2.p
3. Create to PinJoints. One at cpBodyWorld2Local(connector, wheel1.p) and one at cpBodyWorld2Local(connector, wheel2.p)

if this approach is terribly wrong, please say so

bye

### Who is online

Users browsing this forum: No registered users and 7 guests