Box2D Colliding From 1 Direction

Started by
3 comments, last by Zakwayda 14 years, 1 month ago
I'm trying to work on a game and I have an object which I only want to collide with from one direction. I'll try and illustrate my idea below ___________________ ------------------- 0 Ok say the above 'character' tries to jump. I want him to be able to jump up through the object and to not collide with the sides of the object, but rather only collide with the character when it is standing on top of the object. I hope this makes sense, if it doesn't please ask to explain further. Thanks in advance for any help, Luke
Advertisement
Are your objects represented through tiles, or are they defined in objects?
It's crucial to deal with the design of the environment when working
on collision detection. There are many tutorials on colisions out there.

-What is your approach on the "level" objects of yours?
They are just objects, that will be created randomly and as the screen moves up, a new set will be randomly generated so the screen always has blocks across it.

If it helps I am trying to make a sort of clone of doodle jump the game on the iPhone, or with the same base concept anyway.

I am considering just writing my own collision detection method and not using box2d as I don't really need it for this sort of project.
You could just do an ordinary parametric test between a direction vector from the center of your character, and all the nearest blocks.

You could also try and render the non-passable geometry to a texture,
and sample this texture around your character, to check wether he collides
with the blocks.

If your character can jump so fast, that he may pass a block completely, in just one iteration, you should check if the line between the previous location of his solid geometry and the new location passes any solid blocks.

There are really many different approaches to this.
-I hope you find what's best for your specific application
If you've decided not to use Box2D this won't be of much use to you, but I know that the problem you mention (the 'one-sided platform' problem) has been discussed on the Box2D forums, so you might check there to see if you can find any info on the topic. (There might even be a testbed program demonstrating how to create one-sided platforms, but without checking, I can't say for sure.)

This topic is closed to new replies.

Advertisement