Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arcade Circle bodies moving through other bodies. Reproducible. #122

Closed
Arcanorum opened this issue Apr 6, 2017 · 1 comment
Closed
Labels

Comments

@Arcanorum
Copy link

Arcanorum commented Apr 6, 2017

This Issue is about

  • A bug in the API

I'm using 2.7.5.
When a physics body is moving fast enough, it can pass though other bodies that it is supposed to collide with. The velocity that this happens at is not the same for rectangle and circle bodies.

Here it can be seen, from Phaser sandbox. Press space to jump. The rectangle and circle bodies fall and hit the platform below at the same speed, but the circle passes though. When tried with lower values for gravity, this doesn't happen.

/**
 * Generated from the Phaser Sandbox
 *
 * //phaser.io/sandbox/rDpRbHcW
 *
 * This source requires Phaser 2.6.2
 */

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

function preload() {

    game.stage.backgroundColor = '#85b5e1';

    game.load.baseURL = 'http://examples.phaser.io/assets/';
    game.load.crossOrigin = 'anonymous';

    game.load.image('player', 'sprites/phaser-dude.png');
    game.load.image('platform', 'sprites/platform.png');

}

var player;
var player2;
var platforms;
var cursors;
var jumpButton;

function create() {

    player = game.add.sprite(100, 200, 'player');
    player2 = game.add.sprite(150, 200, 'player');

    game.physics.arcade.enable(player);
    game.physics.arcade.enable(player2);

    player.body.collideWorldBounds = true;
    player.body.gravity.y = 200;
    
    player2.body.setCircle(20);
    player2.body.collideWorldBounds = true;
    player2.body.gravity.y = 200;

    platforms = game.add.physicsGroup();

    platforms.create(500, 150, 'platform');
    platforms.create(-200, 300, 'platform');
    platforms.create(400, 450, 'platform');

    platforms.setAll('body.immovable', true);

    cursors = game.input.keyboard.createCursorKeys();
    jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

}

var collideSpeed = 0;
var collideSpeed2 = 0;

function update () {

    game.physics.arcade.collide(player, platforms, function(){
        collideSpeed = player.body.velocity.y;
    });
    game.physics.arcade.collide(player2, platforms, function(){
        collideSpeed2 = player2.body.velocity.y;
    });

    player.body.velocity.x = 0;
    player2.body.velocity.x = 0;

    if (cursors.left.isDown)
    {
        player.body.velocity.x = -250;
        player2.body.velocity.x = -250;
    }
    else if (cursors.right.isDown)
    {
        player.body.velocity.x = 250;
        player2.body.velocity.x = 250;
    }

    if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down))
    {
        player.body.velocity.y = -400;
    }
    
    if (jumpButton.isDown && (player2.body.onFloor() || player2.body.touching.down))
    {
        player2.body.velocity.y = -400;
    }
}

function render () {
    game.debug.text('rect Y velocity: ' + player.body.velocity.y, 8, 140, "#ff00ff");
    game.debug.text('rect X velocity: ' + player.body.velocity.x, 8, 160, "#ff00ff");
    game.debug.text('rect collide speed: ' + collideSpeed, 8, 180, "#ff00ff");
    game.debug.body(player);
    
    game.debug.text('circ Y velocity: ' + player2.body.velocity.y, 408, 140, "#ff00ff");
    game.debug.text('circ X velocity: ' + player2.body.velocity.x, 408, 160, "#ff00ff");
    game.debug.text('circ collide speed: ' + collideSpeed2, 408, 180, "#ff00ff");
    game.debug.body(player2);
}
@samme
Copy link
Collaborator

samme commented Apr 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants