public void doFlockingV2( List <NormalControl> boids, out Vector3 cohesion, out Vector3 speration, out float cohesionAdd) { cohesion = Vector3.zero; speration = Vector3.zero; int tooaway_neighbourCount = 0; int tooclose_neighborCount = 0; NormalControl self = host as NormalControl; foreach (NormalControl item in boids) { float cohesionThreshold = self.solider_Meta_Info.speration_radius + self.solider_Meta_Info.cohesion_radius; float sperateThreshold = self.solider_Meta_Info.speration_radius + item.solider_Meta_Info.speration_radius; ///离自己太远的 //self radius + tolerate radius if (item != host && Vector3.SqrMagnitude(item.transform.position - host.transform.position) > (cohesionThreshold * cohesionThreshold)) { cohesion += item.transform.position; tooaway_neighbourCount++; } //self radius + neighbour radius if (item != host && Vector3.SqrMagnitude(item.transform.position - host.transform.position) < (sperateThreshold * sperateThreshold)) { speration += item.transform.position - host.transform.position; tooclose_neighborCount++; } } if (tooclose_neighborCount != 0) { speration = ((speration / tooclose_neighborCount) * -1.0f).normalized; } else { speration = Vector3.zero; } ///全都远离你? if (tooaway_neighbourCount > (boids.Count / 2)) { cohesionAdd = 0.1f; cohesion = ((cohesion / tooaway_neighbourCount) - host.transform.position).normalized * (1 + cohesionAdd); } else { cohesionAdd = 0f; cohesion = Vector3.zero; } }
public WalkStateV3( string stateName, NormalControl selfControl) { this.stateName = stateName; this.selfControl = selfControl; }
public WalkStateV3( string stateName, NormalControl selfControl) { this.stateName = stateName; this.selfControl = selfControl; }
// Use this for initialization void Start() { normalControl = player.GetComponent <NormalControl>(); reverseGravityControl = player.GetComponent <ReverseGravityControl>(); }