Jump to content

sprite.body.touching.down always FALSE


eloguvnah
 Share

Recommended Posts

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

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

  • 8 months later...

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

 Share

  • Recently Browsing   0 members

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