Jiaoma / chipmunk-physics

Automatically exported from code.google.com/p/chipmunk-physics
MIT License
0 stars 0 forks source link

Collision fails after a few bumps #9

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi.
I've got a problem with a simple collision detection between a box-shaped 
moving object and the borders of my view, modeled with 4 segmented shapes 
attached to a static body.

What steps will reproduce the problem?
1. Build a simple shape (a rectangle) and 4 statics segments among which 
the 
box can move. The 4 borders are the border of my window
2. Apply some impulse to the shape, so that it bounces off the border a 
few times (i.e. the topmost..) 
3. After a few bounces, the object gains speed and it doesn't bounce off 
the border anymore, it just passes through it as if the body/shape was not 
there
4. The behaviour goes away if the segments composing the static body have 
a big radius (say.. 15, or 20).. the behaviour is almost istantaneous 
(after the first bounce the collisions disappears) if the radius is 1. If 
the radius is 5, after a few bounces the collision disappears.

What is the expected output? What do you see instead?

I expect collisions to be still detected and handled.

What version of the product are you using? On what operating system?

Running on IPhone OS 3.1 using Chipmunk 4.1.0

Please provide any additional information below.

Please see full code attached.
As far as I know, these are the relevant snippets of the code:

1) setting up of the space

        space = cpSpaceNew();   

    // Define a gravity vector    
    //inzialmente nullo. La roba non si muove
    space->gravity = cpv( 00,  0);      
    space->elasticIterations = 10;  

    //setup ball and shapes..
    // Create our ball's body with 100 mass and infinite moment   
    ballBody = cpBodyNew(100.0, INFINITY);   

    ///..other setup (i.e. rectangular shape) 
    ballShape->collision_type = 1; // Collisions are grouped by 
types   

    // Add the shape to out space    
    cpSpaceAddShape(space, ballShape);   

    // Create our floor's body and set it's position   
    cpBody *floorBody = cpBodyNew(INFINITY, INFINITY);   

    floorBody->p = cpvzero; 

    // Define our shape's vertexes   
    const cpFloat elast=0.4;
    const cpFloat friction=0.1;
    const int radius=5;
    //add 3 other sides
    //top
    floorShape = cpSegmentShapeNew(floorBody,  cpv(fieldSizeW,416),cpv
(0,416),radius);   
    floorShape->e = elast; floorShape->u = friction; floorShape-
>collision_type = 1;   
    floorShape->data = floor;   
    cpSpaceAddStaticShape(space, floorShape);    

2) Handle accelerometer movement

float fattoreImpulso=3000*variatore*2;

            cpBodyResetForces(ballBody);
            space->gravity = cpv(0,0);

            cpBodyApplyImpulse(ballBody,cpv(fattoreImpulso* 
accX,-fattoreImpulso* accY),cpvzero);
            break;

3) test it, make it bounce at the top or bottom, then tilt the device, 
gain some momentum, make it bounce again.. after a few moments, the 
collision disappears.

4) I've tried changing collision type (i'm not sure what it is for) to no 
avail.

I enclose the relevant files, i't s an UIView. Look for the
- setupChipmunk (for seting up the physics)
- didAccelerate method (movement)

Thank you.
Walter Gamba

Original issue reported on code.google.com by walter.g...@gmail.com on 3 Dec 2009 at 6:40

Attachments:

GoogleCodeExporter commented 8 years ago
I also get this problem for fast-travelling objects. From what I noticed, it 
happens when the object's center penetrates the segment (or other object) where 
its center point gets on the other side. The object gets warped on the other 
side and is able to exit the game area.

This can be temporarily solved by using a smaller time step and more 
iterations, or, as mentioned, increasing the radius of the segments. I know 
this is an old issue, but it still is affecting the latest svn trunk version.

I'm running chipmunk-physics svn r697 on Linux x64, also tested on Linux x86.

Original comment by teh...@gmail.com on 3 Mar 2011 at 7:01