zelcard Posted September 6, 2016 Share Posted September 6, 2016 create: function() { platforms = this.game.add.physicsGroup(); for (var i = 0; i < 5; i++) { platform = platforms.create(this.game.world.centerX, this.game.world.centerY + 300, 'platform') platform.anchor.setTo(0.5, 1); this.game.physics.enable(platform, Phaser.Physics.ARCADE); platform.body.immovable = true; platform.body.checkCollision.up = true; platform.body.checkCollision.down = false; platform.body.stopVelocityOnCollide = false; } player = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY + 260, 'player'); player.anchor.setTo(0.5, 1); this.game.physics.enable(player, Phaser.Physics.ARCADE); player.body.gravity.y = 150; player.body.collideWorldBounds=true; player.body.checkCollision.up = false; player.body.checkCollision.left = false; player.body.checkCollision.right = false; player.body.checkCollision.down = true; }, update: function() { platforms.forEach(this.checkPosition, this); this.game.physics.arcade.collide(player, platforms, this.addScore, null, this); }, checkPosition: function(platform) { if(platform.body.touching.up == true){platform.body.velocity.y = 100;} }, I'm trying to call body.touching.up for every platform that is in-game but it doesn't seem to work. Am I doing something wrong or is this even possible to do using platforms.forEach function? Please note that this is just a part of the code but the basic idea is that I launch player sprite and when it lands on platform, the platform starts to move. I understand that I can do this by checking if player is touching the platform, but I want platforms that are not colliding with player do something as well. Thanks. Link to comment Share on other sites More sharing options...
samme Posted September 6, 2016 Share Posted September 6, 2016 I think you need to move `checkPosition` after `arcade.collide`: http://codepen.io/anon/pen/wzBVvv Because you've set `platform.body.immovable = true`, `arcade.collide` will zero its velocity if it's touching anything. zelcard 1 Link to comment Share on other sites More sharing options...
zelcard Posted September 7, 2016 Author Share Posted September 7, 2016 It works, awesome! Thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts