function ensureCohesionSpeed(boid,surrounding_boids){
	let averagePositionVector = new THREE.Vector3(0,0,0)
	let boidPosition = new THREE.Vector3(boid.position.x,boid.position.y,boid.position.z)
	for (let i=0;i<surrounding_boids.length;i++){
		currentBoid = surrounding_boids[i]
		currentBoidPosition = new THREE.Vector3(currentBoid.position.x,currentBoid.position.y,currentBoid.position.z)
		averagePositionVector.add(currentBoidPosition)
	}
	averagePositionVector.multiplyScalar(1/surrounding_boids.length)
	let speedVector = averagePositionVector.addScaledVector(boidPosition,-1)
	return speedVector.normalize()
}
// Fourth Rule : ensure boids group has cohesion
Fourth Rule : ensure boids group has cohesion
Fourth Rule : ensure boids group has cohesion
function ensureCohesionSpeed(boid,surrounding_boids){
	let averagePositionVector = new THREE.Vector3(0,0,0)
	let boidPosition = new THREE.Vector3(boid.position.x,boid.position.y,boid.position.z)
	for (let i=0;i<surrounding_boids.length;i++){
		currentBoid = surrounding_boids[i]
		currentBoidPosition = new THREE.Vector3(currentBoid.position.x,currentBoid.position.y,currentBoid.position.z)
		averagePositionVector.add(currentBoidPosition)
	}
	averagePositionVector.multiplyScalar(1/surrounding_boids.length)
	let speedVector = averagePositionVector.addScaledVector(boidPosition,-1)
	return speedVector.normalize()
}
function ensureCohesionSpeed ( boid , surrounding_boids ) { let averagePositionVector = new THREE . Vector3 ( 0 , 0 , 0 ) let boidPosition = new THREE . Vector3 ( boid . position . x , boid . position . y , boid . position . z ) for ( let i = 0 ; i < surrounding_boids . length ; i ++ ) { currentBoid = surrounding_boids [ i ] currentBoidPosition = new THREE . Vector3 ( currentBoid . position . x , currentBoid . position . y , currentBoid . position . z ) averagePositionVector . add ( currentBoidPosition ) } averagePositionVector . multiplyScalar ( 1 / surrounding_boids . length ) let speedVector = averagePositionVector . addScaledVector ( boidPosition , - 1 ) return speedVector . normalize ( ) }
Fourth Rule : ensure boids group has cohesion
Fourth Rule : ensure boids group has cohesion