chipmunk collision for falling HERO effect

Official forum for the Chipmunk2D Physics Library.
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

chipmunk collision for falling HERO effect

Post by sunflower »

HI,


I have developing one simple game for iphone using chipmunk and cocos2d in which my HERO is falling from top of the building. And to give falling effect i am using "ScaleTo" Action on sprite. Now, I want to detect the collision with moving object under the building. I am using chipmunk for collision detection. I have attached shape to both objects ( HERO and Moving object). But the problem is because HERO (which is falling down) and moving object sometimes gets into same x,y coordinate while ball is falling so chipmunk detects collision multiple times. I want collision to be detected once HERO reaches to bottom of building.
or what i want is when ScaleTo action finished than only, chipmunk should detect collision or execute collision logic.

I tried using BOOL flag which i am setting on ScaleTo callback and check that flag on collision (if its set than only perform action) but still chipmunk detect collision at-least twice.

I want to know that am I doing something wrong or is there any easier way to do show that HERO is falling and when it reaches bottom of the building it detects collision with other object.

Please help me on this. I am stuck with this. I would really appreciate.

Thanks
Sunflower
Last edited by sunflower on Tue Apr 13, 2010 11:34 am, edited 1 time in total.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by slembcke »

I guess it depends on which version of Chipmunk you are using. Chipmunk 4.x only had a single collision callback that was called every frame that things were touching. Chipmunk 5.x has a much broader set of collision events including a callback that is called only when objects first start touching.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

I am using 5.x. I guess you don't understand my question.

The game has top view (landscape) so you see everything from top ( like palne) and you see that HERO is standing on the building and there is moving object at the ground so i want the jump that hero on that moving object. but in reality when hero jump on that object both are in same X, Y cordinates. so chipmunk detects the collision and it detects multiple times until HERO reaches the ground/bottom and i remove hero from screen.

So, what i want that once it should detect collision only when HERO reaches ground.

I hope that makes you understand the question.

thanks
sunflower
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by slembcke »

So the objects overlap in x and y, but you want Chipmunk to ignore the collision until they have the same z? Chipmunk is strictly a 2D physics engine, so it doesn't know anything about z values though you can give it clues.

Little Big Planet for the PS3 looks as though it also has strictly 2D physics, but has layers for the collisions. You could use the Chipmunk shape's layers property to fake the 3D in this way as well. Only set the bit for the layer on your hero when his z value is in a certain range.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

Hi,

Thanks for quick response. Yes go that right.

I have no idea about cpLayer. I tried to look into it but couldn't find any documentation. Do you know any sample code or documentation about getting understanding of shape's layer?

i really appreciate your help.

Thanks
Sunflower
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by slembcke »

From: http://code.google.com/p/chipmunk-physics/wiki/cpShape
layers: Shapes only collide if they are in the same bit-planes. i.e. (a->layers & b->layers) != 0 By default, a shape occupies all 32 bit-planes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

HI,

I tried to read through wiki page but still i am confused how to use the layer for it. I would really appreciate if you can give me some more information about and how i can implement in my case.

I am stuck with it.

Thanks
Sunflower
User avatar
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by Tam Toucan »

I want collision to be detected once HERO reaches to bottom of building.
or what i want is when ScaleTo action finished than only, chipmunk should detect collision or execute collision logic.

I tried using BOOL flag which i am setting on ScaleTo callback and check that flag on collision (if its set than only perform action) but still chipmunk detect collision at-least twice.
You are wanting to ignore collisions between the hero and an object whilst the hero is in the air. You tried setting a bool flag to indicate that the hero was in the air and that didn't fix the problem. Correct? You say "Chipmun detect collision at-least twice", do you mean it detected it whilst the hero was still in the air? If so then you got the code wrong somewhere; either no setting/resetting the bool, not checking the bool correctly etc.

If you mean Chipmunk detected the collision only when the hero wasn't in the air, but did so more than once then yes it would, but you must know that already.

Layers won't do anything different from what you have done already. All you would be doing is setting the hero layer value so that they can't collide with anything whilst in the air and then resetting it when they are back on the ground. Your setting of the bool does exactly the same thing.

Layers could be handy if you wanted to implement multiple colision height layers e.g. you have 32 "heights" the hero can be at and as they jump you set the layer attribute accordingly. They could then land on or jump over objects at different heights. So the layer values would something like

Code: Select all

ground = 0x00000001        (bit 0)
"1 high building" = 0x00000003   (bits 0 and 1)
"6 high" building = 0x0000003f   (bits 0 to 6)
"2 high floating platform at height 10" = 0x00000a00  (bits 10 and 11)
Hero at height 31 = 0x80000000 (bit 31)
As I said though, layers aren't going to do anything different than your bool. You would still need to set the layer when the hero is in the air and reset it when the jump ends (just like the bool). So need to know exactly why/how the bool flag didn't work
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

Thanks Tam for taking time and posting reply. I really appreciate it.
You understand correct. Let me make is some clear for you.
I am using Cocos2d and chipmunk. I am achieve falling effect using Cocos2d Scale-to Action. So it looks like HERO is going down. So before i do Scale-to i set bool to FALSE and when this Action finished i set bool to TRUE and remove that HERO from screen and set bool again to FALSE and in between chipmunk detects the collision twice. What i am thinking is it might be because of frame-rate, which is is 1/60 so before I HERO remove from screen and set bool to False collision get called twice.

Let me know if that makes sense to you. I can post code if you want.

I really appreciate your help.

Thanks
Sunflower
User avatar
Tam Toucan
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by Tam Toucan »

Yeah I think some code would be handy. I'll post a bunch of stuff to show what kind of info I'm looking for.

First. Let's see if I'm clear on the sceanrio. The game is top down. The Hero is ontop of a building (say a square). When they faill off the top of the building (move off the square) you use scaleTo to reduce the size of the sprite as they fall. Moving along the ground there is some object (say a square net). If at the end of the scaleTo action they are colliding with the moving object then you want to do something (say, not kill the player).

What I don't understand is your description of the bool. You say you set the bool to true when the action finishes (so do mean you set it in the update method when the t param is 1? You remove the hero, does that effect the chipmunk object (e.g. data member points to something that's gone)? Then you set it to false (when?) and in-between (need to know what code is run "in-between"). Also how is the bool begin used?

Here's what I thought you would be doing. To ensure collisions between the hero and the moving object are ignored until the scaleTo action has finished (hero has hit the ground) the hero as a bool "hitGround" which is only set to true when the scaleTo action finishes. The collision handler for the hero and the moving object checks this bool and ignores the collision unless true.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests