0
votes

I am using cocos2d-x and box2d. I am detecting collisions with box2d and all seems to go well except one little thing. For some reason when the objects collide they are bouncing off one another. Now I was reading on this a little bit and found that restitution causes this. So I opened up physics editor and set both objects to have a restitution of 0.0. It was still doing it so I researched a bit more and found that have a static/kinematic body would stop this from happening as well so on the one object I was able to do this because it is not applying gravity and such but with the other object I had to leave it as dynamic so that it would apply the gravity to it. So now when it hits the kinematic body stops but the dynamic body is still bouncing off of the other object. It seems to only do it on places where the vertices that it hits at is at an angle. Is there any real way to tell it not to move at all. When this happens it pushes my main character off of the screen.

UPDATE: Ok so maybe I am going about this wrong. I am just trying to learn so I figured a "flappy bird" project would be a good learning experience. So I figured I needed a physics engine so I went with box2d so the bird would fall by itself. Then I am just moving an image of a baseball bat (to the left because the bird is fixed at x=birdheight / 2 and y=screenheight / 2) right now to test collision. On the first go the collision was hitting the square so I looked into how to change the rectangle. In doing so I came across physics editor. So then I updated the images and got a box2d export for the fixtures. So then I redid the bat image from a simple sprite to a box2d body so that I could detect the collision with the new rectangle that is correct. When i first implemented the detection worked good but both objects were being pushed in the direction the screen was scrolling (to the left). So then after some reading I converted the bat image to be a static body which then stopped pushing the bat but the bird still moves. I am only using box2d essentially for making the bird fall by itself and to detect the collision of the rectangle to be more precise than a simple square of the image. Am I completely doing this wrong or is there something I am missing to get the collision detection to stop at the exact location of the intersection?

1
if you are using cocos2d-x v3 have you looked at the new PhysicsEngine?GameDeveloper
I am not sure what you are referring to. I just downloaded Physics Engine about a week ago and when I click check for updates it says that none are available. I am also not sure how this would solve my problem?ngreenwood6
How much bounce are we talking about? Box2D is built for speed, not accuracy, and the result is often not exactly what it would ideally be. I am not aware of any way to completely eliminate bouncing, but if both fixtures have a restitution of 0 the bounce should be very minimal. You could try decreasing the time step length.iforce2d
If I reduce the time step length wouldn't that reduce the speed of the world? Sorry just a noob at game programming :)ngreenwood6
I just updated the question and am hoping someone can shed some light on this subject. I have been able to figure out everything else that I have looked into except the collision detection. I really want it to stop at the exact location of intersection and would really appreciate any help I can get. All of the tutorials I have looked at and source code I have found do not have intersection collision detection and is just based on the original "rectangle" or "circle".ngreenwood6

1 Answers

0
votes

Read about sensors, it is a thing you are looking for. http://www.iforce2d.net/b2dtut/sensors If you use Physics Editor then you have to only check the "sensor" checkbox on te right panel and you are done.