I am trying figure out how to construct a loop similar in screen below for a car game I am making. I having a hard time figuring out how to do part 1 where the loop intersect and car passes by. Maybe some kind of collisions filtering? Please any suggestions?
how to construct loops in box2d
Re: how to construct loops in box2d
Yes, you can do this with collision filtering. You will need to split the loop into three sections: the entry, the middle part, and the exit. Then you can turn off collisions with the exit section when the car is approaching the loop, and turn off collisions with the entry section as the car leaves the loop. You would also need some sensor fixtures to detect when to switch between these two states.
As a start, perhaps you could look at the pinball example in the RUBE sample source code (this is in the SFML, cocos2d, and cocos2d-x downloads). There are two cases where this same type of collision filter switching occurs to let the ball enter and exit ramps to make it look like it goes 'above' other walls. You can look at the RUBE scene file to see how the wall sections have been split up, and where the sensor fixtures are placed. The source code should have comments explaining how these are used. Let me know if you have any trouble with that.
As a start, perhaps you could look at the pinball example in the RUBE sample source code (this is in the SFML, cocos2d, and cocos2d-x downloads). There are two cases where this same type of collision filter switching occurs to let the ball enter and exit ramps to make it look like it goes 'above' other walls. You can look at the RUBE scene file to see how the wall sections have been split up, and where the sensor fixtures are placed. The source code should have comments explaining how these are used. Let me know if you have any trouble with that.
-
- Posts: 41
- Joined: Thu May 29, 2014 5:01 am
Re: how to construct loops in box2d
Very quick response and help! Thank you!