ygunawan95

How to check all member of group location

Recommended Posts

Hi i need some help with my school assignment

so what i want to do is to kill the children at the same time if all the children's y position more than 820. or if i can check all the position of the children or the group ( i dont think that possible). 

animals.forEach(function(animal) {   
		   	var z=0;
		   	if (animal.y > 820)
		    { z++;     
		    	console.log(z);
		     }
			
			if (z>6)
				{animal.kill();}
			}

			);

the number of the children is 5 and the problem is the number of z is always 1 therefor the animal.kill() never been process. 

thought?? or do you have better way to check the position?

 

really appreciate the help guys thanks 

 

Share this post


Link to post
Share on other sites

Hey - you need to check "Y" instead of "Z" and then you can remove all of them:
just loop though children as you do and check:

 

var toRemove = [];
animals.forEach(function(animal) {   
  var z=0;
  if (animal.y > 820){
    console.log(y);
    toRemove(animal)
  }
});
toRemove.forEach(function(animalToRemove){
  animalToRemove.destroy()
});


 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.