Welding two bodies together

Official forum for the Chipmunk2D Physics Library.
Post Reply
michaelg1987
Posts: 9
Joined: Sun Feb 15, 2009 10:31 am
Contact:

Welding two bodies together

Post by michaelg1987 »

Originally I thought that I could solve this issue by just using shapes and offsets. However, I need to be able to remove the constraints later on so that the bodies can move independently. Is there a way to apply a constraint so that not only the distance between two bodies is held constant, but so that the angle is as well? Basically so they move together like one body. I cannot do this with shapes, as I need to be able to in some cases remove the constraint and manipulate them independently.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Welding two bodies together

Post by slembcke »

Yes and no.

You can attach their positions together using a Pivot joint and their angles using a Gear Joint with a ratio of 1.0. The problem is that joints are adding extra constraints to the system which means it will use extra CPU and they will never quite feel solid.

I would merge and split the bodies personally. It's a bunch of extra math, but the end result is much nicer.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
georgeburns
Posts: 4
Joined: Sun Jan 10, 2010 10:28 pm
Contact:

Re: Welding two bodies together

Post by georgeburns »

2 pivot joints with offset anchors?
michaelg1987
Posts: 9
Joined: Sun Feb 15, 2009 10:31 am
Contact:

Re: Welding two bodies together

Post by michaelg1987 »

It just seems crazy to me that such a thing doesn't exist. I'll try the two pivots I guess. Besides, how can I merge/separate bodies if they have polyShapes in them? There's no getOffset method for polyShapes.
michaelg1987
Posts: 9
Joined: Sun Feb 15, 2009 10:31 am
Contact:

Re: Welding two bodies together

Post by michaelg1987 »

It's worth noting that the physics is only used for collision detection here really. There's no game mechanic that relies on me accurately calculating the positions of bodies. I guess I can just manually update the angle and position each time.
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Welding two bodies together

Post by dieterweb »

If you are only using collison detection with chipmunk, you will have to update the positions of the shapes yourself anyway. So no need to bend them together in chipmunk.
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Welding two bodies together

Post by slembcke »

You can't change the offset easily of a polyshape no. You would have to create a new polyshape with the offset applied.

The reason that the joint you want doesn't exist is that it's actually several constraints in one. Writing a joint that does that would basically do exactly what a pivot joint and the gear joint does, solving the position and angle separately. Two pivot joints will work too. You will probably run into stability issues though if you don't put each the joints at the center of gravity of both bodies.

If you are only using it for collision detection then how are you moving the bodies so that the joints work?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
michaelg1987
Posts: 9
Joined: Sun Feb 15, 2009 10:31 am
Contact:

Re: Welding two bodies together

Post by michaelg1987 »

Well I mean to say that while the physics engine is completely added, I really only am using it for the callbacks and very basic motions. I still do need to move a few objects, and when they move, a lot of other objects move. The other alternative seems to be just doing a manual rotation of everything each frame (get parent's rotation, calculate offset after being rotated by that much, apply own rotation).
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Welding two bodies together

Post by slembcke »

The reason why I ask is because joints will only work if you are using the solver properly. Calling cpSpaceStep() dutifully and moving objects around by not setting their positions directly.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
michaelg1987
Posts: 9
Joined: Sun Feb 15, 2009 10:31 am
Contact:

Re: Welding two bodies together

Post by michaelg1987 »

I call cpSpaceStep() as I should, and as of now I don't set positions -- but I may want to set angles in the future. It's dawning on me that I'm really just using this for collision detection, really, and so would it be faster rather than to simulate each projectile with the chipmunk, for me to manually control their positions (position += velocity * delta for instance) and then just run queries to see if they're over anything?
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests