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
37.12k stars 7.1k forks source link

Immovable object is stopped by a non immovable object #5785

Closed Kosmoon closed 1 year ago

Kosmoon commented 3 years ago

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);
}
photonstorm commented 3 years ago

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.

Kosmoon commented 3 years ago

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.

photonstorm commented 3 years ago

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.

Kosmoon commented 3 years ago

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

photonstorm commented 1 year ago

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