Jump to content

Phaser arcade physics BUG


Hadik
 Share

Recommended Posts

Hello, I found bug in arcade physics.

 

When I make self collide in group (balls will colide between self) and set follow the mouse (like liquid following mouse) they will create letter T, why ? Why they not make simple circle ? Like P2JS physics (I cant use this physics, becuase when I create 200+ balls FPS are at 0)

 

 

What I want ? Simple liquide (very simple) just balls with colide with other balls and follow the mouse and create circle from small balls (or other shape but no T ???... )

 

There is screenshoot: http://prntscr.com/aj1v7r

 

Or just go into this example> http://phaser.io/examples/v2/arcade-physics/move-towards-object#gv

 

set balls count to  500 and into update add 


    game.physics.arcade.collide(balls);

 

It will do same think..Why?

There is code: 

var game = new Phaser.Game(600, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update, render: render});


function preload() {

    game.load.image('ball', 'assets/liquid.png');

}

var balls;
var ballx;
var bounds;

function create() {
    game.time.advancedTiming = true;
    game.time.deltaCap = 0.016;
    bounds = new Phaser.Rectangle(100, 100, 400, 400);
    game.physics.startSystem(Phaser.Physics.Arcade);
    
    balls = game.add.physicsGroup(Phaser.Physics.ARCADE);
    for (var i = 0; i < 1000; i++)
    {
        var ball = balls.create(bounds.randomX, bounds.randomY, 'ball');
        game.physics.enable(ball, Phaser.Physics.ARCADE);
        ball.body.setSize(10, 10);
    }

}

function update() {
    game.physics.arcade.collide(balls);
    game.physics.arcade.collide(balls, bounds);
        if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){
            balls.forEach(game.physics.arcade.moveToPointer, game.physics.arcade, false, 200);
        }
}

function render() {
    game.debug.text("FPS: " + this.game.time.fps, 5, 10);

}

 

Link to comment
Share on other sites

As near as I can tell, this isn't really a bug.  It's a limitation of arcade physics due to a couple of contributing factors.  For one, arcade physics uses axis aligned bounding boxes for its physics simulations.  Imagine it in real life:

Take 500 wooden building blocks that aren't allowed to rotate, and try to form a circle out of them.  It would be a lot more complicated than just pushing them all towards the center of your circle.

Another other limitation is the way collide works.  It checks a group of objects against a group of objects.  It "un-overlaps" them if it finds them overlapped.  But it won't necessarily see if the un-overlapping  creates another overlap.  This unfortunately allows objects to end up occupying the same space.  This is a more apparent limitation when you have many many objects, like with the 500 balls in your example.  After that happens, when the engine tries to "un-overlap" things in the next pass, it's going to tend to push them out along one axis rather than the other.  This is what creates the cross shape you're seeing.

Link to comment
Share on other sites

Thank you for greate answer and explain problematic.

 

Is there any solution how have 500 balls in the game and simulate for example water ? (with gravity) For example change time between collision check (P2 physics), or set some other body propertios which can improve performance ?

 

I working on game when will be liquids enemy and they will absorb other entities.

Link to comment
Share on other sites

Without knowing anything about you requirements, I believe that you shouldn't use collide. It is an expensive operation so avoid that as often as possible.

Create 1000 balls as you do, add to physics group

Forget about the update checking "if spacebar", try to create a callback instead.

Each ball will still move to your pointer, but without collision detection They will probably just be move into the same point then.

If you don't want them to be in the the same point, or as I can understand, you want a circle, then calculate the coordinate, use Pythagoras Theorem for placement. It is fairly easy. And by doing your own circle you can recreate the radius to reflect number of balls incoming :)

 

NB:  I haven't created anything i Phaser yet, I'm just reading the API, but I do have about 20 years of programming experience :) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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