Jump to content

body.touching always return false


aladine
 Share

Recommended Posts

Hello everyone, 

So am trying to make a mini clone of Super Craft Box and am facing a problem with the touching method inside the body class,

it always return false for the 4 directions

the log message :

 

 

Object {none: true, up: false, down: false, left: false, right: false}

 

the thing is that am having this problem only with a group members cause it works perfectly for the player but not for the enemy, 

 

this is the part of the code where i handle everything about the enemy object : 

//------------------------------------------------------------////------------------------------------------------------------////------------------------------------------------------------///*>> Zombie Methods << *///setupfunction zombieSetting(){	zombies = game.add.group();	createAzombie();}function createAzombie(){	zombie = zombies.create(368,0,zombieImage);	var ranDir = Math.floor((Math.random()*10)+1);	if(ranDir>5){		zombie.scale.x =1;	}else{		zombie.scale.x = -1;	}	zombie.body.velocity.x = zombieSpeed * zombie.scale.x;	zombie.body.bounce.y = 0.5;	zombie.body.gravity.y=12;	zombie.anchor.setTo(0.5,0.5);}//collision handlingfunction zombieCollision(){	game.physics.collide(zombies,platforms); 	game.physics.overlap(zombies,limitZones,zombieFlip,null,this); 		game.physics.overlap(zombies,rageZones,zombieRage,null,this);	console.log(zombie.body.touching);}//flip direction when hit a wallfunction zombieFlip(zombie,limitZones){	zombie.body.velocity.x = -zombie.body.velocity.x ;	zombie.scale.x =-zombie.scale.x;	}//kill when hit with a bulletfunction killZombie(bullet,zombie){	zombie.kill();	bullet.kill();}//Respeawn with more power when enter rage zonefunction zombieRage(zombie,rageZones,i){	var addSpeed=0;	if(zombie.body.velocity.x<400){		var ranSpd = Math.floor((Math.random()*10)+1);		if(ranSpd>5){			addSpeed =100;		}else{			addSpeed=50;		}	}	var tmpSpeed =Math.abs(zombie.body.velocity.x )+addSpeed;	var tmpScale = -zombie.scale.x;	tmpSpeed = tmpSpeed*tmpScale;	var tmpImage = zombie.key;	zombie.kill();		if(tmpImage=='z1'){		tmpImage= 'z2';	}else if(tmpImage=='z2'){		tmpImage= 'z3';	}		var zombie = zombies.create(368,0,tmpImage);	zombie.body.velocity.x = tmpSpeed ;	zombie.scale.x = tmpScale;	zombie.body.bounce.y = 0.3;	zombie.body.gravity.y=12;	zombie.anchor.setTo(0.5,0.5);}//spawn new zombie in time function spawnZombie(){	if(game.time.now > spawnTime){		createAzombie()		spawnTime = game.time.now + spawnSpeed;	}}/*>> End of Zombies<< *///------------------------------------------------------------////------------------------------------------------------------////------------------------------------------------------------//

and this is my update method : 

function update() {	playerCollision();	playerControl();	bulletCollision()	zombieCollision();	spawnZombie();}

the rest of the code and the game are here when you can test, see the logs and the entire game code  : Link  

 

PS : 

am very new with JavaScript, so please if you read my entire code and found some bad habits then please tell me about it, will really appreciate that. 

 

Update: 

i forgot something, 

i want to check the touching direction so i will not use another platform group (limitZone) to revert the enemy direction, so what i really want to do is this :

game.physics.overlap(zombies,platforms,flip,null,this);function flip(){	if(zombie.body.touching.right || zombie.body.touching.left){		zombie.body.velocity.x = -zombie.body.velocity.x ;		zombie.scale.x =-zombie.scale.x;		}}

and if you play the game now, you will notice that there is some enemies that when they hit the platform they completely stop moving which is the reason of all this mess

 

thank you 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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