Jump to content

Simple top-down physics questions


Recommended Posts

Hi, im trying to make a top-down game where (among other things) you can push around boxes.

I'd like it to be very simple in the sense that the player always moves with constant speed, pushing boxes shouldn't slow him down and boxes should stop immediately once they're not being pushed anymore.

Can this be achieved with arcade physics?

The biggest issue however is when the player pushes multiple boxes against the world border. Once there is no room anymore, the player can still move in that direction and push boxes 'into' other boxes.

Is it possible that all entities always act solid at all times, so that when the player pushes multiple boxes in a direction where there is no room, he simply doesn't move any further?

Below is what i've tried so far in the sandbox:

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

var game = new Phaser.Game(config);
var player;
var group;
var cursors;

function preload () {
    this.load.image('block', 'assets/sprites/block.png');

function create () {

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

    group = this.physics.add.group({
        dragX: 500,
        dragY: 500,
        collideWorldBounds: true

    var block1 = group.create(100, 300, 'block');
    var block2 = group.create(200, 300, 'block');
    var block3 = group.create(300, 300, 'block');
    var block4 = group.create(400, 300, 'block');
    var block4 = group.create(500, 300, 'block');

    player = this.physics.add.sprite(500, 500, 'block');
    this.physics.add.collider(player, group);

function update() {

    if (cursors.left.isDown && !cursors.right.isDown){
    if (cursors.right.isDown && !cursors.left.isDown) {
    if (cursors.up.isDown && !cursors.down.isDown){
    if (cursors.down.isDown && !cursors.up.isDown) {


Thanks in advance!

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...