-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Incomplete collisions in Arcade when pushing objects #4175
Description
- Phaser Version: v3.16.0 Beta 2
- Physics: Arcade
- Browser: Chromium
There is a collision bug when 1 object pushes another - at some moment objects start to go through each other, like there is no collision at all.
In the example code below (for labs.phaser.io) I have 2 ground platforms and all stars falling on it, and a player. Plus collisions between everything, even between stars themselves. Player initially is in the middle of the screen and stars.
If I move to the right - stars go through the right platform like there is no collision - it's a 1'st issue.
If I move to the left - I'm able to join only 2 stars - all other acts like physicsless and player/stars just go through them. So you get max 2 stars in a row - it's a 2'nd issue.
What can I do to make collisions always work as expected? Can you please fix that?
Example Test Code
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var player;
var stars;
var platforms;
var cursors;
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('sky', 'src/games/firstgame/assets/sky.png');
this.load.image('ground', 'src/games/firstgame/assets/platform.png');
this.load.image('star', 'src/games/firstgame/assets/star.png');
this.load.spritesheet('dude', 'src/games/firstgame/assets/dude.png', { frameWidth: 32, frameHeight: 48 });
}
function create ()
{
this.add.image(400, 300, 'sky');
platforms = this.physics.add.staticGroup();
platforms.create(400, 568, 'ground').setScale(2).refreshBody();
platforms.create(900, 520, 'ground');
player = this.physics.add.sprite(300, 450, 'dude');
player.setCollideWorldBounds(true);
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'turn',
frames: [ { key: 'dude', frame: 4 } ],
frameRate: 20
});
this.anims.create({
key: 'right',
frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }),
frameRate: 10,
repeat: -1
});
cursors = this.input.keyboard.createCursorKeys();
stars = this.physics.add.group({
key: 'star',
repeat: 11,
setXY: { x: 12, y: 0, stepX: 70 }
});
this.physics.add.collider(player, platforms);
this.physics.add.collider(stars, platforms);
this.physics.add.collider(player, stars, collideElem, null, this);
this.physics.add.collider(stars, stars, collideElem, null, this);
}
function collideElem(obj1, obj2) {
obj2.body.setVelocityX(0);
obj2.body.setVelocityX(0);
}
function update ()
{
if (cursors.left.isDown)
{
player.setVelocityX(-160);
player.anims.play('left', true);
}
else if (cursors.right.isDown)
{
player.setVelocityX(160);
player.anims.play('right', true);
}
else
{
player.setVelocityX(0);
player.anims.play('turn');
}
if (cursors.up.isDown && player.body.touching.down)
{
player.setVelocityY(-330);
}
}