Chipmunk+Cocos2D JS Bindings: My character bounces randomly

Official forum for the Chipmunk2D Physics Library.

Chipmunk+Cocos2D JS Bindings: My character bounces randomly

Postby peterwilli » Tue Feb 25, 2014 8:10 am

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.
peterwilli
 
Posts: 2
Joined: Tue Feb 25, 2014 8:01 am

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

Postby peterwilli » Tue Feb 25, 2014 9:50 am

Nevermind, I was doing this first because I found it at a website (http://www.noodlecake.com/15/fixing-your-timestep-with-cocos2d-and-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.
peterwilli
 
Posts: 2
Joined: Tue Feb 25, 2014 8:01 am

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

Postby Dredok » Sat Apr 11, 2015 1:09 pm

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:
Dredok
 
Posts: 2
Joined: Sat Apr 11, 2015 1:08 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron