Page 1 of 1

Chipmunk+Cocos2D JS Bindings: My character bounces randomly

Posted: Tue Feb 25, 2014 8:10 am
by peterwilli
Hi Everyone,

I kinda got this problem since I started using ChipMunk and it's propably something very simple that I just don't see.
I have a game running in Cocos2D with Javascript bindings (Javascript that calls c++ API)

It's currently using chipmunk as physics engine. The Problem I'm having is that I start making my floor to prevent falling of the screen:

Code: Select all

function() {
    var body, shape, size;
    size = cc.Director.getInstance().getWinSize();
    body = new cp.Body(1000, Infinity);
    body.setPos(cc.p(size.width / 2, g_groundHight / 2));
    shape = new cp.BoxShape(body, size.width, g_groundHight);
    shape.setSensor(false);
    shape.setFriction(0);
    shape.setElasticity(0);
    shape.setCollisionType(kTagWall);
    this.space.addShape(shape);
    this.wallBody = body;
    return null;
  }
g_groundHight is just the number 64.

This all works and my floor box is created, the problem I'm having is that once my player gets on the ground it starts bouncing up in the air really high at random times.

It's quite annoying and I've tried a lot, but haven't found any real answer to this problem.
I hope you guys might have an idea of what's going on here, any more code needed will be given, and thanks in advance for helping!

The behaviour is not like bouncing by the way, because when my player falls down again and hits the floor, there's no new bounce. It just happens to shoot in the air randomly.

Also, my timestep is fixed to 1/60 so I dont think it's because of framedrops or anything else.

Re: Chipmunk+Cocos2D JS Bindings: My character bounces rando

Posted: Tue Feb 25, 2014 9:50 am
by peterwilli
Nevermind, I was doing this first because I found it at a website (http://www.noodlecake.com/15/fixing-you ... -chipmunk/) (Ported that to JS)

But now I'm doing this.space.step(pRate) where pRate is 1.0/60 and now it's fully working.

Re: Chipmunk+Cocos2D JS Bindings: My character bounces rando

Posted: Sat Apr 11, 2015 1:09 pm
by Dredok
Just wanted to say that this was bothering to me too!

Fixing the timestep was the way to go !

Now my characters rest in peace on the ground :lol: