def get_flocking_heading(agent_name, neighbours): # initialise the heading vector for this agent heading_vector = [0, 0, 0] separation_heading_vector = get_separation_heading(agent_name, neighbours) cohesion_heading_vector = get_cohesion_heading(agent_name, neighbours) alignment_heading_vector = get_alignment_heading(neighbours) # apply the weighting to each heading vector and then add them altogether # to get the overall heading vector global separation_weight global cohesion_weight global alignment_weight separation_heading_vector = vectorMath.vector_scale( separation_heading_vector, separation_weight) cohesion_heading_vector = vectorMath.vector_scale(cohesion_heading_vector, cohesion_weight) alignment_heading_vector = vectorMath.vector_scale( alignment_heading_vector, alignment_weight) heading_vector = vectorMath.vector_add(heading_vector, separation_heading_vector) heading_vector = vectorMath.vector_add(heading_vector, cohesion_heading_vector) heading_vector = vectorMath.vector_add(heading_vector, alignment_heading_vector) return heading_vector
def get_flocking_heading(agent_name, neighbours): # initialise the heading vector for this agent heading_vector = [0, 0, 0] separation_heading_vector = get_separation_heading(agent_name, neighbours) cohesion_heading_vector = get_cohesion_heading(agent_name, neighbours) alignment_heading_vector = get_alignment_heading(neighbours) # apply the weighting to each heading vector and then add them altogether # to get the overall heading vector global separation_weight global cohesion_weight global alignment_weight separation_heading_vector = vectorMath.vector_scale(separation_heading_vector, separation_weight) cohesion_heading_vector = vectorMath.vector_scale(cohesion_heading_vector, cohesion_weight) alignment_heading_vector = vectorMath.vector_scale(alignment_heading_vector, alignment_weight) heading_vector = vectorMath.vector_add(heading_vector, separation_heading_vector) heading_vector = vectorMath.vector_add(heading_vector, cohesion_heading_vector) heading_vector = vectorMath.vector_add(heading_vector, alignment_heading_vector) return heading_vector
def do_flocking_behaviour(agent): # initialise our heading to 0 agent_heading_vector = [0, 0, 0] #find all the neighbours of this agent neighbours = find_agents_within_distance(agent,agent_near_distance) #only get a new heading if there any agents close by if len(neighbours): agent_heading_vector = get_flocking_heading(agent, neighbours) #even if we have no neighbours we still want to move towards the goal goal_heading_vector = get_goal_heading(agent) global goal_weight goal_heading_vector = vectorMath.vector_scale(goal_heading_vector, goal_weight) agent_heading_vector = vectorMath.vector_add(agent_heading_vector, goal_heading_vector) #we now have the desired heading agent_heading_angle = vectorMath.get_heading_angle_from_vector(agent_heading_vector) ##print agent,agent_heading_angle #agent.turn_towards_heading(agent_heading_angle)# decided not to use this agent.set_agent_heading(agent_heading_angle) #used this instead. better.
def do_flocking_behaviour(agent): # initialise our heading to 0 agent_heading_vector = [0, 0, 0] #find all the neighbours of this agent neighbours = find_agents_within_distance(agent, agent_near_distance) #only get a new heading if there any agents close by if len(neighbours): agent_heading_vector = get_flocking_heading(agent, neighbours) #even if we have no neighbours we still want to move towards the goal goal_heading_vector = get_goal_heading(agent) global goal_weight goal_heading_vector = vectorMath.vector_scale(goal_heading_vector, goal_weight) agent_heading_vector = vectorMath.vector_add(agent_heading_vector, goal_heading_vector) #we now have the desired heading agent_heading_angle = vectorMath.get_heading_angle_from_vector( agent_heading_vector) ##print agent,agent_heading_angle #agent.turn_towards_heading(agent_heading_angle)# decided not to use this agent.set_agent_heading(agent_heading_angle) #used this instead. better.