views:

118

answers:

1

hi,

I have some box,creating using box2d,which restitution's are set to zero.but when they fall over one another there appear bounce event.but i don't want that...i want them not move when fall over another.it can be done if i switch off gravity.but i also want gravity.here is my code

UIImage *imageOfSnowV1 = [ UIImage imageNamed:[NSString stringWithFormat:@"Object%d.png",currentlySelected]];
    CCTexture2D  *texOfSnowV1 = [[ [CCTexture2D alloc] initWithImage:imageOfSnowV1 ] autorelease];
    CCSprite *sprite = [CCSprite spriteWithTexture:texOfSnowV1  rect:CGRectMake(0, 0, 32, 32)];
    [self addChild:sprite];
    sprite.position = ccp(p.x, p.y);
    sprite.tag=[temp intValue];


    // Define the dynamic body.
    //Set up a 1m squared box in the physics world

    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;

    bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
    bodyDef.userData = sprite;
    b2Body *bodyS = world->CreateBody(&bodyDef);

    // Define another box shape for our dynamic body.

    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box




    b2MassData massData;
    massData.mass = 0.1f;
        bodyS->SetMassData(&massData);


    // Define the dynamic body fixture.
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox; 
    fixtureDef.density = 50.0f;
    fixtureDef.restitution=0.0f;
    fixtureDef.friction = 0.01f;


    bodyS->CreateFixture(&fixtureDef);

can anyone help me?

A: 

As I remember box2d by default uses maximal restitution of colliding objects so even if you have dynamic body restitution set to 0 if the static body have any larger than 0 then that restitution will be used for collision, you could modify b2MixRestitution function to meet your needs.

Cheers, Krzysztof Zabłocki

Krzysztof Zabłocki
@ Krzysztof Zabłocki:i also tried that..already modify the inline function....but no luck
Rony
maybe in your collision delegate set to sleep the dynamic object? that's a hack but may work.
Krzysztof Zabłocki
hahaha...seems every one thinks in same way...also tried this..
Rony
i did this void BeginContact(b2Contact* contact) { b2Body* bodyA = contact->GetFixtureA()->GetBody(); b2Body* bodyB = contact->GetFixtureB()->GetBody(); if ( bodyA->GetType()==b2_dynamicBody bodyB->SetAwake(false); } }
Rony