void Awake() { current = this; //create static map obstaclesPotentialsMap = new PFStaticPotentialsMap(MapConfig.origin, MapConfig.width, MapConfig.height); obstacleFields = new PFPotentialField[obstacle.Length]; for (int i = 0; i < obstacleFields.Length; i++) { obstacleFields[i] = new PFRadialPotentialField() { type = PF_TYPE.Repell, position = obstacle[i].transform.position, potential = 60, gradation = 10, }; obstaclesPotentialsMap.addPotentialField(obstacleFields[i]); } goalField = new PFRadialPotentialField() { type = PF_TYPE.Attract, position = goal.position, potential = MapConfig.width + MapConfig.height, gradation = 1 }; }
void Awake() { current = this; //create static map obstaclesPotentialsMap = new PFStaticPotentialsMap(MapConfig.origin, MapConfig.width, MapConfig.height); obstacleFields = new PFPotentialField[obstacle.Length]; for (int i = 0; i < obstacleFields.Length; i++) { obstacleFields[i] = new PFRadialPotentialField() { type = PF_TYPE.Repell, position = obstacle[i].transform.position, potential = 60, gradation = 10, }; obstaclesPotentialsMap.addPotentialField(obstacleFields[i]); } goalField = new PFRadialPotentialField() { type = PF_TYPE.Attract, position = goal.position, potential = MapConfig.width + MapConfig.height, gradation = 1 }; }
private void addPotentail(PFPotentialField curfield, int multiplier) { for (int i = (int)Mathf.Max(origin.x, (curfield.position.x - curfield.potentialBoundsHalfWidth)); i < Mathf.Min((origin.x + width), (curfield.position.x + curfield.potentialBoundsHalfWidth)); i++) { for (int j = (int)Mathf.Max(origin.y, (curfield.position.y - curfield.potentialBoundsHalfHeight)); j < Mathf.Min((origin.y + height), (curfield.position.y + curfield.potentialBoundsHalfHeight)); j++) { map[i][j] += multiplier * curfield.getLocalPotential(i - (int)curfield.position.x, j - (int)curfield.position.y); } } }
private void addPotentail(PFPotentialField curfield, int multiplier) { for (int i = (int)Mathf.Max(origin.x, (curfield.position.x - curfield.potentialBoundsHalfWidth)); i < Mathf.Min((origin.x + width), (curfield.position.x + curfield.potentialBoundsHalfWidth)); i++) { for (int j = (int)Mathf.Max(origin.y, (curfield.position.y - curfield.potentialBoundsHalfHeight)); j < Mathf.Min((origin.y + height), (curfield.position.y + curfield.potentialBoundsHalfHeight)); j++) { map[i][j] += multiplier * curfield.getLocalPotential(i - (int)curfield.position.x, j - (int)curfield.position.y); } } }
public void removePotentialField(PFPotentialField curfield) { addPotentail(curfield, -1); }
public void addPotentialField(PFPotentialField curfield) { addPotentail(curfield, 1); }
// Use this for initialization void Start() { //create static map obstaclesPotentialsMap = new PFStaticPotentialsMap(MapConfig.origin, MapConfig.width, MapConfig.height); obstacleFields = new PFPotentialField[obstacles.Length]; for (int i = 0; i < obstacleFields.Length; i++) { obstacleFields[i] = new PFRadialPotentialField() { type = PF_TYPE.Repell, position = obstacles[i].position, potential = 100, gradation = 10 }; obstaclesPotentialsMap.addPotentialField(obstacleFields[i]); } goalField = new PFRadialPotentialField() { type = PF_TYPE.Attract, position = goal.position, potential = MapConfig.width + MapConfig.height, gradation = 1 }; agent1 = new PFAgent() { type = PF_TYPE.Repell, position = agent1_tran.position, potential = 4, gradation = 1 }; agent2 = new PFAgent() { type = PF_TYPE.Repell, position = agent2_tran.position, potential = 4, gradation = 1 }; agent1_tran.gameObject.GetComponent<BaseControl_2>().agent = agent1; agent1_tran.gameObject.GetComponent<BaseControl_2>().neighbour_agent = agent2; agent2_tran.gameObject.GetComponent<BaseControl_2>().agent = agent2; agent2_tran.gameObject.GetComponent<BaseControl_2>().neighbour_agent = agent1; agent1Mp = new PFDynamicPotentialsMap(MapConfig.origin, MapConfig.width, MapConfig.height); agent1Mp.addPotentialField(goalField); agent1Mp.addPotentialField(agent2); agent2Mp = new PFDynamicPotentialsMap(MapConfig.origin, MapConfig.width, MapConfig.height); agent2Mp.addPotentialField(goalField); agent2Mp.addPotentialField(agent1); agent1.addStaticPotentialsMap(obstaclesPotentialsMap); agent1.addDynamicPotentialsMap(agent1Mp); agent2.addStaticPotentialsMap(obstaclesPotentialsMap); agent2.addDynamicPotentialsMap(agent2Mp); }
public void removePotentialField(PFPotentialField curField) { fields.Remove(curField); }
public void addPotentialField(PFPotentialField curField) { fields.Add(curField); }
public void removePotentialField(PFPotentialField curfield) { addPotentail(curfield, -1); }
public void addPotentialField(PFPotentialField curfield) { addPotentail(curfield, 1); }