Adding/removing shapes on object after initial creation

Official forum for the Chipmunk2D Physics Library.

Adding/removing shapes on object after initial creation

Postby gigibyte » Thu Feb 11, 2016 3:43 pm

Hi,

I'm using Chipmunk-objective with cocos2d. I need to have a compounded object with non-overlapping, similar sized components, that are attached together, but can be dynamically modified (adding or removing one or more components). Think it as Tetris blocks, that each is composed of 3 or 4 square box, and move together, but I want to be able to weld them together or break them apart dynamically.

I tried to have each components as an individual object, and held them together using two joints that limit both distance and rotation. But when I have multiple such components weld together in such way, with many joints, the blocks are not perfectly stable (sprite would show inperfect distance/angle), and as a whole, their movement is somethings very strange. I see that in Cocos2d-x has a joint called weld joint, but such does not exist under Cocos2d-spriteBuilder. Is this is the expected behavior? I think I remember seeing somewhere that using joints to stick objects together is not good.

I also have a second solution in mind, but want to ask before I try it out. I can create each component as a shape and attach them to a single object. Since each object can have multiple shapes, it is ok that way. But to my understanding, once an object is created, its associated shape list cannot be further modified. I see no exposed API to add or remove or modify attached shapes. I see there is an unsafe api to change existing shapes' property, but not adding or removing one. So I don't know if my second solution would work or not.

Does anyone have similar experience or ideas on what I am trying to do?

Thanks,

Mark,
gigibyte
 
Posts: 1
Joined: Thu Feb 11, 2016 3:27 pm

Re: Adding/removing shapes on object after initial creation

Postby froggerjohn » Thu Feb 11, 2016 8:32 pm

I haven't used Chipmunk-objective, but the ChipmunkJS port features public addShape() and removeShape() methods for a body. Internally, seems like it should be ok, as long as you recalculate things like mass, center of gravity, moment of inertia.
froggerjohn
 
Posts: 7
Joined: Sat Jan 17, 2015 10:11 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron