phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.94k stars 7.08k forks source link

Pushable `false` bodies still move when circle shaped #5617

Closed kainage closed 2 months ago

kainage commented 3 years ago

Version

Description

Bodies are still pushable when both pushable values are set to false when either one of them is a circle. Works fine only when both are rectangles.

Example Test Code

var config = {
    type: Phaser.AUTO,
    width: 864,
    height: 632,
    parent: 'phaser-example',
    backgroundColor: '#2d2d2d',
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 0 },
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update,
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.setPath('assets/sprites');
    this.load.image('blockANP');
    this.load.image('blockBNP');
}

var cursors
var left

function create ()
{
    this.physics.world.setBounds(0, 0, 864, 632);

    cursors = this.input.keyboard.createCursorKeys();

    left = this.physics.add.image(200, 196-16, 'blockANP').setCollideWorldBounds().setInteractive();
    var right = this.physics.add.image(600, 196-16, 'blockBNP').setCollideWorldBounds().setInteractive();

    left.setBounce(0.5);
    right.setBounce(0.5);

    // If either one of these are a circle they will get pushed.

    left.setCircle(32)
    right.setCircle(32)

    left.setPushable(false);
    right.setPushable(false);

    this.physics.add.collider(left, right);
}

function update ()
{
    if (cursors.left.isDown)
    {
        left.setVelocityX(-160);
    }
    else if (cursors.right.isDown)
    {
        left.setVelocityX(160);
    }
    else if (cursors.up.isDown)
    {
        left.setVelocityY(-160);
    }
    else if (cursors.down.isDown)
    {
        left.setVelocityY(160);
    }
    else {
        left.setVelocity(0)
    }
}
dartinger commented 2 years ago

I can confirm the problem wasn't solved until version 3.55.2. (OS: Linux/Ubuntu)

pixel-fabian commented 2 years ago

I am also struggling with this issue.

zekeatchan commented 2 months ago

This issue has been resolved.

Arcade body circles setPushable method updated to include collisions between two circles. Setting the Arcade Body setPushable(false) method for circle bodies prevents them from being pushed by other circle bodies.

This will be included in the next update. Thank you for bringing this to our attention!