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:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

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.
That is correct. Thats exactly what i am checking. In collision method i am checking for Boolean value is its false than ignore collision and once it true i should kill the HERO (wich remove HERO out of screen along with chipmunk shape).
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?
if you know cocos2d engine than you can implement callback function on each action end. So what i m doing it i set hitGround = false before action begins and at the end (in callback function)i set hitGround=ture. and than remove HERo from screen with chipmunk object and set hitGround=false. In the same callback function i call another Action which is to change HERO's size to original and after it gets removed. I don't have code with me right now but i will post once i will reach home in the evening. but here sequence of execution of code.

* set hitground = false
* COCOS2D = scale to action
* at end of action callbackfunction get called and in callback function
* set hitGround = true
* remove HERo from screen with chipmunk shape.
* set hitGround = false
* call another COCOS2D function to set to original size

so as soon i set hitGround = true collision function get called twice and i think ( I am not 100%) because of frame rate. I am not sure weather i am doing something wrong or implantation of what i want is wrong.

I WILL POST CODE WHEN I WILL REACH HOME.

Thanks for taking time and looking into my problem. I would really appreciate that.

Thanks
Sunflower
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

HI,

I found the solution of it. Actually, Its not solution but get around of that problem. Now, I change "hitGround" flag to false in collision callback function itself when i found first time "hitGround" flag is true.

let me know if that's correct way to do it or not? Now because of lots of collision callback function and checking for flag on each call makes little slow.

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 »

Well I don't quite follow what you have done, but if you are rejecting the collisions in the begin callback then that's pretty much the best you can do. Layers would reject it slightly earlier, but all you would be saving is the hash lookup of the begin function and the function call itself.

If you are rejecting it elsewhere e.g. postSolve callback, then there is a lot of savings to be made. If you are still on 4.X then move to the latest!

You say it's slow? it will only call the callback when there is a collision e.g. the hero is "above" the platform and as they fall the collision is called every pass until they actually hit the ground. Why should that be slow?
sunflower
Posts: 13
Joined: Wed Jan 20, 2010 12:54 pm
Contact:

Re: chipmunk collision for falling HERO effect

Post by sunflower »

Well I don't quite follow what you have done, but if you are rejecting the collisions in the begin callback then that's pretty much the best you can do. Layers would reject it slightly earlier, but all you would be saving is the hash lookup of the begin function and the function call itself.
Yes, using hitGround flag i was rejecting collision on begin. But than i used Shape layers to do the same and now it doesn't even call collision when its in the air. and once it reaches the ground i change its layer to make sure it collide. So everything looks perfect now.

Does that make sense?

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 »

Yep layers will give the earlest rejection.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests