eloguvnah Posted June 30, 2014 Share Posted June 30, 2014 Hey guys, I'm back in the saddle working on my game but since updating my existing game to Phaser 2, I'm scratching my head on a few things. The first thing is that my grouped sprites are not registering the touching.down as they hit the layer. What am I doing wrong here?JumperBot.prototype = Object.create(Phaser.Group.prototype);JumperBot.prototype.constructor = JumperBot;JumperBot.prototype.update = function() { this.forEach(updateJumperBots, this, true);}// Update for each JumperBotfunction updateJumperBots(bot) { var playerPosX = player.x; var playerPosY = player.y; this.game.physics.arcade.collide(bot, layer); this.game.physics.arcade.overlap(bot, player.laser, jumperBotLaserShot); this.game.physics.arcade.collide(bot.jumperBullets, layer, layerShoot); this.game.physics.arcade.overlap(bot.jumperBullets, player.shield, jumperBulletShield); if ( playerPosX > bot.x && bot.body.touching.down ) { bot.facing = 'right'; } if ( playerPosX < bot.x && bot.body.touching.down ) { bot.facing = 'left'; } // JUMP if ( bot.body.touching.down ) { console.log('touching down'); if ( bot.facing == 'left' ) { bot.animations.play('jump-left'); bot.body.velocity.y = -375; bot.body.velocity.x = -150; } else if ( bot.facing == 'right' ) { bot.animations.play('jump-right'); bot.body.velocity.y = -375; bot.body.velocity.x = 150; } } // Check if Jumper is between 20 and -20 Y of the player var playerBotYdiff = playerPosY - bot.y; if ( playerBotYdiff < 20 && playerBotYdiff > -20 && bot.exists ) { bot.fire; }} Link to comment Share on other sites More sharing options...
marvster Posted June 30, 2014 Share Posted June 30, 2014 Physics.arcade.collide() will prevent from touching as it will prevent from overlap [touch has to come with overlap]. Possible solutions discussed can be found here:http://www.html5gamedevs.com/topic/7004-check-if-a-body-is-next-to-another-body-but-not-overlapping/http://www.html5gamedevs.com/topic/7263-how-to-determine-nearbytouching-objects-for-interaction-eg-npc/ markergreen 1 Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 You need to use body.blocked.down instead of body.touching.down to detect when something is actually solidly in contact with a surface. You can also use body.onFloor() which does the same check. The body.touching property is meant to be used inside the collision callback to determine which side is colliding. hoskope, san40511 and eloguvnah 3 Link to comment Share on other sites More sharing options...
eloguvnah Posted June 30, 2014 Author Share Posted June 30, 2014 Hm... still no luck, but I just realized I'm having issues with my layer as well... It's very strange -- sometimes the bullets from my player will collide with the tiles on my layer and sometimes it won't.I'm guessing there's a connection there. This may be deeper than I thought. Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 Sorry I've just this minute updated the post, see if my new suggestion works. Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 Also, if you're running the collide routines separately for each bot, and there are several bots, this may cause problems. You should try to call these routines from the main game update loop, checking groups of bots/bullets against the layer once per update. If you're calling collide multiple times for the same things you may run into issues. eloguvnah 1 Link to comment Share on other sites More sharing options...
eloguvnah Posted June 30, 2014 Author Share Posted June 30, 2014 Awwww yea!That was it -- body.blocked will be stored in my brain matter now. Thanks! And thanks for the heads up on the collides -- I didn't even think about how many times it'd be checking for those collides. Perfect! Thanks! Link to comment Share on other sites More sharing options...
markergreen Posted March 27, 2015 Share Posted March 27, 2015 Yeah, thanks Phaser Moderator. You helped me go from this problem to the below solution. Problem: game.physics.arcade.collide(player1,team);game.physics.arcade.collide(player2,team);game.physics.arcade.collide(player3,team); Solution:game.physics.arcade.collide(team,team); Link to comment Share on other sites More sharing options...
Recommended Posts