oliversb Posted September 5, 2017 Share Posted September 5, 2017 How do I get the body to only collide with left or right bounds? I am using arcade physics and tried to convert this over with from a post using a different physics system. 'function createPreviewBounds(x, y, w, h) { var sim = game.physics.arcade; customBounds.left = new Phaser.Body({ mass: 0, position: [ x, y ], angle: 1.5707963267948966 }); customBounds.left.addShape(new Plane()); customBounds.right = new Phaser.Body({ mass: 0, position: [ x + w, y ], angle: -1.5707963267948966 }); customBounds.right.addShape(new Phaser.Plane()); // customBounds.right.shapes[0].collisionGroup = mask; customBounds.top = new Phaser.Body({ mass: 0, position: [ x, y ], angle: -3.141592653589793 }); customBounds.top.addShape(new Phaser.Plane()); // customBounds.top.shapes[0].collisionGroup = mask; customBounds.bottom = new Phaser.Body({ mass: 0, position: [ x, y + h ] }); customBounds.bottom.addShape(new Phaser.Plane()); // customBounds.bottom.shapes[0].collisionGroup = mask; sim.world.addBody(customBounds.left); sim.world.addBody(customBounds.right); sim.world.addBody(customBounds.top); sim.world.addBody(customBounds.bottom); }' I wrote this code were I wanted to createPreviewBounds '//create bounds var bounds = new Phaser.Rectangle(100, 100, 400, 400); customBounds = { left: null, right: null, top: null, bottom: null }; createPreviewBounds(bounds.x, bounds.y, bounds.width, bounds.height);' I cannot seem to find the right constructor. Thanks Link to comment Share on other sites More sharing options...
samme Posted September 6, 2017 Share Posted September 6, 2017 Arcade Physics bodies collide only with the World bounds and with other bodies. So I think your options are Use collideWorldBounds=true Use 4 blank, physics-enabled sprites to form a rectangle Create a Phaser.Rectangle and write your own collision method Link to comment Share on other sites More sharing options...
Recommended Posts