phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Immovable object is stopped by a non immovable object

Open Kosmoon opened this issue 2 years ago • 4 comments

  • Phaser Version: 3.55.2

Description

An immovable object with a velocity is stopped by a non immovable object when squishing it against another immovable object without velocity. expected behavior and seen behavior before 3.5: the immovable object with a velocity should keep its velocity and go through the non immovable object.

Example Test Code

paste the code bellow in: https://labs.phaser.io/edit.html?src=src/physics/arcade/sprite%20vs%20immovable.js&v=3.55.2

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    parent: 'phaser-example',
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 0 },
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var wall;
var sprite;
var sprite2

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('mushroom', 'assets/sprites/mushroom2.png');
    this.load.image('flectrum', 'assets/sprites/flectrum.png');
}

function create ()
{
    wall = this.physics.add.image(200, 300, 'flectrum').setImmovable();
    sprite = this.physics.add.image(500, 300, 'mushroom').setVelocity(-100, 0).setImmovable()
    sprite2 = this.physics.add.image(300, 300, 'mushroom').setImmovable(false);
}

function update ()
{
    this.physics.world.collide(wall, sprite, function () {
        console.log('hit?');
    });
    this.physics.world.collide(wall, sprite2);
    this.physics.world.collide(sprite, sprite2);
}

Kosmoon avatar Jul 20 '21 09:07 Kosmoon

Immovable just means it won't pick up velocity from the body it collides with, it doesn't mean it cannot be stopped. In this case, stopping is the correct thing for it to do. Passing right through the other body prior to 3.50 was clearly a bug.

photonstorm avatar Jul 20 '21 11:07 photonstorm

Immovable just means it won't pick up velocity from the body it collides with, it doesn't mean it cannot be stopped. In this case, stopping is the correct thing for it to do. Passing right through the other body prior to 3.50 was clearly a bug.

Oh ok, so it was a fixed bug. Nonetheless, updating to 3.5 is breaking this wanted behavior in my game. Is there a way to achieve this in 3.5 ? An immovable object which can be collided by other objects but never stopped by them.

Kosmoon avatar Jul 20 '21 11:07 Kosmoon

Use an overlap check instead of a collide one? If nothing should ever stop it, it doesn't need to collide with the other objects, just detect when it is over them.

photonstorm avatar Jul 20 '21 12:07 photonstorm

Use an overlap check instead of a collide one? If nothing should ever stop it, it doesn't need to collide with the other objects, just detect when it is over them.

In my game the player should be able to interact with it (jumping on it, being pushed by it, so it needs to collide with it), but it should not stop it if being squished by it, instead it should go through the player and kill him. For the moment i'm using a trick that detects if the moving immovable sprite is stopped and i give it back its initial velocity + changing a little its position to compensate the frames where it was stuck. I'm not satisfied with this solution. This should maybe be a forum post instead

Kosmoon avatar Jul 20 '21 12:07 Kosmoon

Closing this off as it was more a discussion than an issue. Feel free to re-open in the forum / Discord if still relevant.

photonstorm avatar Nov 29 '22 18:11 photonstorm