"Disabling" ChipmunkShape collision when touched?

Official forum for the Chipmunk2D Physics Library.
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

"Disabling" ChipmunkShape collision when touched?

Post by neigaard »

I have some ChipmunkShape's that act as platforms where different ChipmunkObject's can "land" on. I am using the brilliant ChipmunkMultiGrab to be able to move those objects around, but for some of those platforms (most of them but not all of them) I want to be able to drag the objects right through them as if they did not exist, so they should stop existing but only for the objects that are being dragged, and as soon as I let go of the object they should interact as normal.

Is there a way to do this? I was thinking about using different collision types and changing those types for the dragged object runtime, but will that work and how? Can I get a notification on the objects that are dragged or do I have to find that my self?

Thank you
Søren
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by slembcke »

Hmm. So the best way to do it might be to switch out the shape's collision type with one that has a begin callback that returns FALSE. That way any object that it's colliding with when it is dragged it will continue to pass through. If you drag it halfway through another shape and release it, it won't suddenly pop out. If you don't care about the popping, you can set the layers bitmask to 0, then it won't collide with anything.

In order to do that, you'll need to know when your shape is grabbed or released in order to change the collision type or layers. I'll whip up a change quick this morning that will let you do that. Actually somebody else asked to have a similar feature implemented a couple weeks ago and I totally forgot about it. :-\ Oops. I'll have to dig through my email and see if I can find them.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by neigaard »

That sounds great! Look forward to the change that will let me know when a object is grabbed/released :)

Thank you
Søren
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by neigaard »

slembcke have you had time to whip up a change for me?

Thank you
Søren
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by slembcke »

No I haven't done it yet, sorry. This has been sort of a bad week for me. Starting it right now though.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by slembcke »

I pushed the changes to the ChipmunkPro git repository. There are instructions to check it out on the downloads page if you need them. http://chipmunk-physics.net/downloads.php

What I changed is that the beginLocation:, updateLocation: and endLocation: methods all return a ChipmunkGrab object if the touch is tracking a grabbed shape. From the ChipmunkGrab, you can get the latest touch location, the grabbed shape and I also added a user data pointer for anything else you might want to track along with the touch.

So for you, if beginLocation: returns a grab, change the collision info on that shape (maybe cache the original data using the ChipmunkGrab.data pointer if it's not constant), then when endLocation: returns a grab, reset it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by neigaard »

I get a error when trying to fetch from the git repository for Chipmunk Pro, I get the following error:

error: The requested URL returned error: 401 (curl_result = 22, http_code = 401, sha1 = 0ca4d05c64f5775c35b95c2c3eb696b1164983f8)
error: Unable to find 0ca4d05c64f5775c35b95c2c3eb696b1164983f8 under http://chipmunkPro014@chipmunk-physics. ... unkPro.git
Cannot obtain needed object 0ca4d05c64f5775c35b95c2c3eb696b1164983f8
while processing commit 528d4e0611829cf7a2d29bb6a1a8e463c44adbdd.
error: Fetch failed.

I am using this command:
git clone --recursive http://MyUser@chipmunk-physics.net/rele ... unkPro.git

Thank you
Søren
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by slembcke »

An HTTP 401 status is an authentication error. Are you sure you entered the login information correctly including replacing the "MyUser" placeholder?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by neigaard »

I have been away from this for a while, but Im on it again :)

When you say I should switch out the shape's collision type with one that has a begin callback that returns FALSE, then how should I do that? Simply create a NSObject with a method named "begin" that returns FALSE?

And the other method you talk about, set the layers bitmask to 0, what layer is that?

Thank you
Søren
neigaard
Posts: 36
Joined: Tue Oct 25, 2011 7:38 am
Contact:

Re: "Disabling" ChipmunkShape collision when touched?

Post by neigaard »

I have tried to implement this, now I have a shelf-shape that the object-shape collides with when not dragged, and I want to disable this collision when the object-shape is dragged. So I have set the shelf-shape collisionType to the scene object and tries to set the object-shape collisionType to that same scene object when dragged, but it does not work for me. I have pasted the code for the ccTouchesBegan and ccTouchesEnded here under. It might be that the object-shape is using collisionType or group and there fore the if/else, but it does not work for any of the types.

Code: Select all

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	for(UITouch *touch in touches) {
        ChipmunkGrab *grabObj = [multiGrab beginLocation:TouchLocation(touch)];
        if(grabObj) {
            CCLOG(@"ccTouchesBegan: We have a grabObj");
            GrabCollisionHelper *gch = [[GrabCollisionHelper alloc] init];
            if(grabObj.grabbedShape.collisionType) {
                CCLOG(@"ccTouchesBegan: We have a grabObj - type");
                gch.collisionObj = grabObj.grabbedShape.collisionType;
                gch.isGroup = NO;
                grabObj.grabbedShape.collisionType = self;
            } else {
                CCLOG(@"ccTouchesBegan: We have a grabObj - group");
                gch.collisionObj = grabObj.grabbedShape.group;
                gch.isGroup = YES;
                grabObj.grabbedShape.group = self;
            }
            grabObj.data = gch;
        }
    }
}

Code: Select all

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	for(UITouch *touch in touches) {
        ChipmunkGrab *grabObj = [multiGrab endLocation:TouchLocation(touch)];
        if(grabObj) {
            CCLOG(@"ccTouchesEnded: We have a grabObj");
            GrabCollisionHelper *gch = grabObj.data;
            if(gch.isGroup) {
                CCLOG(@"ccTouchesEnded: We have a grabObj - group");
                grabObj.grabbedShape.group = gch.collisionObj;
            } else {
                CCLOG(@"ccTouchesEnded: We have a grabObj - type");
                grabObj.grabbedShape.collisionType = gch.collisionObj;
            }
            
        }
    }
}
Now the logging I get is this:

ccTouchesBegan: We have a grabObj
ccTouchesBegan: We have a grabObj - type
ccTouchesEnded: We have a grabObj
ccTouchesEnded: We have a grabObj - type

I am wondering if that the two UITouch objects is teasing me here, or if I can not use this method at all? The reason I am trying this is that I want the object-shape to go through some shelf-shape's but not all shelf-shape's, and thus I figured that just setting the collision type to the same for the object-shape's and the correct shelf-shape's would work?

Thank you
Søren
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests