Jump to content

Ninja bounce effect


Keenic
 Share

Recommended Posts

  • 2 weeks later...

I'm *pretty* sure what you're seeing is Ninja physics trying to separate the boxes and the platform. They overlap a little bit and then they get separated. Arcade physics has the same problems. AFAIK there's not a way to fix that besides using a different physics engine like P2.

I think you can try calling the collision handlers multiple times in an update to give things a chance to settle. Maybe try that first?

Link to comment
Share on other sites

I have this in update

// Blocks and platforms collision
this.game.physics.ninja.collide(this.game.blocks, this.game.platforms, this.blockCollision.bind(this));

// Blocks collision
for (let i = 0; i < this.game.blocks.children.length; i++){
    for (let j = 0; j < this.game.blocks.children.length; j++){
        if (i == j) continue;
        this.game.physics.ninja.collide(this.game.blocks.children[i], this.game.blocks.children[j], this.blockCollision.bind(this));
    }
}

Well, if its a physics bug I think its ok.

Thanks for answer.

Link to comment
Share on other sites

You don't need to iterate the group like that. You can just pass the group in like this:

 this.game.physics.ninja.collide(this.game.blocks, this.game.blocks, this.blockCollision, null, this);

Also, you don't want to bind your this.blockCollision method multiple times in update. Each time you do that it'll make a new function. That puts a lot of pressure on the garbage collector and will probably make your game stutter. The fifth parameter of ninja.collide is the callbackContext; in other words, it's the "this" value for your callback. This will have the same effect as calling bind but should run better.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...