Welding two bodies together
-
- Posts: 9
- Joined: Sun Feb 15, 2009 10:31 am
- Contact:
Welding two bodies together
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.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Welding two bodies together
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.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 4
- Joined: Sun Jan 10, 2010 10:28 pm
- Contact:
Re: Welding two bodies together
2 pivot joints with offset anchors?
-
- Posts: 9
- Joined: Sun Feb 15, 2009 10:31 am
- Contact:
Re: Welding two bodies together
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.
-
- Posts: 9
- Joined: Sun Feb 15, 2009 10:31 am
- Contact:
Re: Welding two bodies together
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.
-
- Posts: 176
- Joined: Fri Feb 27, 2009 7:12 am
- Location: Germany
- Contact:
Re: Welding two bodies together
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]
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Welding two bodies together
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?
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Sun Feb 15, 2009 10:31 am
- Contact:
Re: Welding two bodies together
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).
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Welding two bodies together
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Sun Feb 15, 2009 10:31 am
- Contact:
Re: Welding two bodies together
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?
Who is online
Users browsing this forum: No registered users and 4 guests