Chipmunk PhysicsSprite Elasticity

Chipmunk PhysicsSprite Elasticity
0.0 0



So i’ve been playing around with the tests that came with cocos2d html and want to know
if i can disable the elacticity/bouncyness of a Physics sprite and the floor/walls, which means i want only the gravity remaining.
I set the elasticity value to 0 but it worked only half way :slight_smile:

for examle in Chimunk Sprite Test

// init physics
ChipmunkSprite.prototype.initPhysics = function() {
    var space = ;
    var staticBody = space.staticBody;

    // Walls
    var walls = [ new cp.SegmentShape( staticBody, cp.v(0,0), cp.v(winSize.width,0), 0 ),               // bottom
            new cp.SegmentShape( staticBody, cp.v(0,winSize.height), cp.v(winSize.width,winSize.height), 0),    // top
            new cp.SegmentShape( staticBody, cp.v(0,0), cp.v(0,winSize.height), 0),             // left
            new cp.SegmentShape( staticBody, cp.v(winSize.width,0), cp.v(winSize.width,winSize.height), 0)  // right
    for( var i=0; i < walls.length; i++ ) {
        var shape = walls[i];
        shape.setElasticity(0);   // Elasticity -> 0
        space.addStaticShape( shape );

    // Gravity
    space.gravity = cp.v(0, -100);

ChipmunkSprite.prototype.createPhysicsSprite = function( pos ) {
    var body = new cp.Body(1, cp.momentForBox(1, 48, 108) );
    body.setPos( pos ); body );
    var shape = new cp.BoxShape( body, 48, 108);
    shape.setElasticity( 0 );                    // Elasticity -> 0
    shape.setFriction( 100 ); shape );

    var sprite = cc.PhysicsSprite.create(s_pathGrossini);
    sprite.setBody( body );
    return sprite;

Is it possible or should i use another approach, thx in advance and
thx a lot for this framework


In addition to elasticity of bodies, you also need to set the “correction force”.

Physics engine works this way, an object that moves from A to B by its velocity, and because in digital world, there is no analog movement, object jumps from frame to frame
when an object calculates its new position , it checks to see if it has collided with something, collision happens when objects “intersects” another, this cannot happen in real life, your hand cannot go through walls etc

So what should physics engine do when something intersects? it has to correct them! do this by exerting force on intersected objects and propel them in opposite direction, how much force should the physics engine exerts? well, you could set it,
this is the chipmunk manual, go there and search for “cpSpaceGetCollisionBias”


thx for the answer,

i checked their docs and forums and they seem to have exactly what i need :slight_smile:
ill post it here if i come up with something usefull