// Use this for initialization void Start() { steeringBasics = GetComponent <SteeringBasics>(); wander = GetComponent <Wander2>(); cohesion = GetComponent <Cohesion>(); separation = GetComponent <Separation>(); velocityMatch = GetComponent <VelocityMatch>(); sensor = transform.Find("Sensor").GetComponent <NearSensor>(); }
// Use this for initialization void Start() { separation = this.GetComponent <Separation>(); arrive = this.GetComponent <Arrive>(); //align = this.GetComponent<Align>(); velocityMatching = this.GetComponent <VelocityMatch>(); velocityOutput = new SteeringOutput(); avoidance = this.GetComponent <ObstacleAvoidance>(); //m_droneGO.GetComponent<Rigidbody>().AddForce(new Vector3(Random.Range(0,50), Random.Range(0, 50), Random.Range(0, 50)),ForceMode.VelocityChange); }
// Use this for initialization void Start() { steeringBasics = GetComponent<SteeringBasics>(); wander = GetComponent<Wander2>(); cohesion = GetComponent<Cohesion>(); separation = GetComponent<Separation>(); velocityMatch = GetComponent<VelocityMatch>(); sensor = transform.Find("Sensor").GetComponent<NearSensor>(); }
void Start() { //Inicializamos las estructuras necesarias de otros componentes enemy = GameObject.Find(enemyName).GetComponent <static_data>(); kineticsEnemy = enemy.kineticsAgent; kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; //Inicializamos movimientos velMatch = new VelocityMatch(kineticsAgent, kineticsEnemy, MaxAcceleration, timeTotarget); }
public override SteeringOutput getSteering() { SteeringOutput steering = new SteeringOutput(); //Direction to target Vector3 direction = target - character.position; float distance = direction.magnitude; //Check if we are there if (distance < targetRadius) { VelocityMatch getToZero = new VelocityMatch(this.character, new Vector3(0.0f, 0.0f, 0.0f), 5.0f); steering = getToZero.getSteering(); return(steering); } //If we are outside the slow radius, go max speed float targetSpeed; if (distance > slowRadius) { targetSpeed = maxSpeed; //Otherwise calculate scaled speed } else { targetSpeed = maxSpeed * distance / slowRadius; } //Target velocity combines speed & direction Vector3 targetVelocity = direction.normalized * targetSpeed; //Acceleration tries to match target velocity steering.linear = targetVelocity - character.velocity; steering.linear /= timeToTarget; //Clamp acceleration if (steering.linear.magnitude > maxAcceleration) { steering.linear = steering.linear.normalized * maxAcceleration; } //Return steering data return(steering); }
Steering getDefaultSteering2(Entry e) { e.bird.maxSpeed = 30f; (e.bird as Starling).transform.Find("Sphere").gameObject.SetActive(false); var separation = new Separation(e.bird, flock, 5f, -0.5f); var cohesion = new Cohesion(e.bird, flock, 30f, -0.5f); var velMatch = new VelocityMatch(e.bird, flock, 20f, -0.5f); var seek = new Cohesion(e.bird, anchorFlock, float.MaxValue, -1f); // move towards the anchor var flee = new Separation(e.bird, anchorFlock, 10f, -1f); // move towards the anchor separation.aknnApproxVal = 1.0; cohesion.aknnApproxVal = 1.0; velMatch.aknnApproxVal = 25.0; separation.maxNeighborhoodSize = 5; cohesion.maxNeighborhoodSize = 10; velMatch.maxNeighborhoodSize = 5; var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"}); var blended = new BlendedSteering[2]; blended[0] = new BlendedSteering(e.bird, new BehaviorAndWeight(obstacleAvoidance, 1f)); blended[1] = new BlendedSteering(e.bird, new BehaviorAndWeight(separation, 2f), // 0 new BehaviorAndWeight(cohesion, 1f), // 1 new BehaviorAndWeight(velMatch, 0.5f), // 2 new BehaviorAndWeight(seek, 1.25f), // 3 new BehaviorAndWeight(flee, 2f) ); return new PrioritySteering(1f, blended); }
Steering getDefaultSteering(Entry e) { e.bird.maxSpeed = 7.5f; (e.bird as Starling).transform.Find("Sphere").gameObject.SetActive(true); var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"}); var separation = new Separation(e.bird, flock, 5f, 0f); var cohesion = new Cohesion(e.bird, flock, 75f, 0f); cohesion.aknnApproxVal = 25f; cohesion.maxNeighborhoodSize = 15; var velMatch = new VelocityMatch(e.bird, flock, 20f, 0.0f); velMatch.aknnApproxVal = 50f; var bbox = new Bounds(new Vector3(1162, 113, 770), new Vector3(500, 150, 500)); var wander = new SteeringBehaviors.Wander(e.bird, e.bird.maxSpeed, 30f, 50f, bbox); wander.theta = UnityEngine.Random.Range(0f, 360f); var blended = new BlendedSteering[3]; blended[0] = new BlendedSteering(e.bird, new BehaviorAndWeight(obstacleAvoidance, 1f)); blended[1] = new BlendedSteering(e.bird, new BehaviorAndWeight(separation, 1f)); blended[2] = new BlendedSteering(e.bird, new BehaviorAndWeight(wander, 0.85f), // 0 new BehaviorAndWeight(cohesion, 0.90f), new BehaviorAndWeight(velMatch, 0.50f)); return new PrioritySteering(1f, blended); }
// Start is called before the first frame update void Start() { //DATOS DE PERSONAJE kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; //SEPARATION INITIALIZATION //buscamos a todos los pokemones GameObject[] allPokemons = GameObject.FindGameObjectsWithTag("Pokemon"); //vamos a usar solo los pokemones que participan en flock GameObject[] pokemons = Array.FindAll(allPokemons, c => c.GetComponent <static_data>().flocker); //Inicializamos las estructuras necesarias de otros componentes for (int i = 0; i < pokemons.Length; i++) { if (pokemons[i].name != name) //solo me interesan los pokemones que no son yo { targets_kin_sepa.Add(pokemons[i].GetComponent <static_data>().kineticsAgent); } } Kinetics[] targets_sep = targets_kin_sepa.ToArray(); separation = new Separation(kineticsAgent, targets_sep, threshold, maxAccelSep); separation.weigth = 3f; //VELOCITY MATCH INITIALIZATION enemyVel = GameObject.Find(enemyNameVel).GetComponent <static_data>(); kineticsEnemyVel = enemyVel.kineticsAgent; velMatch = new VelocityMatch(kineticsAgent, kineticsEnemyVel, MaxAccelVel, timeTotargetVel); velMatch.weigth = 1f; //COHESION INITIALIZATION //Inicializamos las estructuras necesarias de otros componentes for (int i = 0; i < pokemons.Length; i++) { targets_trans_cohe.Add(pokemons[i].transform); } Transform[] targets_cohe = targets_trans_cohe.ToArray(); maxSpeedCohe = agent.maxspeed; cohesion = new Cohesion(kineticsAgent, targets_cohe, maxAccelCohe, maxSpeedCohe, targetRadiusCohe, slowRadiusCohe, timeToTargetCohe); cohesion.weigth = 1.5f; //BLEND INITIALIZATION //mezclamos nuestros comportamientos para crear fllock behaviors[0] = separation; behaviors[1] = velMatch; behaviors[2] = cohesion; blendFlock = new BlendedSteering(behaviors, maxAccelBlend, maxAngularBlend); }
Steering getDefaultSteering(Entry e, Flock flock) { var separation = new Separation(e.bird, flock, _separationDistance, -0.5f); var cohesion = new Cohesion(e.bird, flock, _cohesionDistance, -0.5f); var velMatch = new VelocityMatch(e.bird, flock, _velocityMatchDistance, -0.5f); var anchorCohesion = new Cohesion(e.bird, anchorFlock, float.MaxValue, -1f); // move towards the anchor var anchorSeparation = new Separation(e.bird, anchorFlock, 25f, -1f); var anchorVelocityMatch = new VelocityMatch(e.bird, anchorFlock, float.MaxValue, -1f); separation.aknnApproxVal = _separationAknnVal; cohesion.aknnApproxVal = _cohesionAknnVal; velMatch.aknnApproxVal = _velocityMatchAknnVal; separation.maxNeighborhoodSize = separationK; cohesion.maxNeighborhoodSize = cohesionK; velMatch.maxNeighborhoodSize = velocityMatchK; var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"}); var blended = new BlendedSteering[2]; blended[0] = new BlendedSteering(e.bird, new BehaviorAndWeight(obstacleAvoidance, 1f)); blended[1] = new BlendedSteering(e.bird, new BehaviorAndWeight(separation, _separationWeight), // 0 new BehaviorAndWeight(cohesion, _cohesionWeight), // 1 new BehaviorAndWeight(velMatch, _velocityMatchWeight), // 2 new BehaviorAndWeight(anchorCohesion, _cohesionToAnchorWeight), // 3 new BehaviorAndWeight(anchorSeparation, _separationFromAnchorWeight), // 4 new BehaviorAndWeight(anchorVelocityMatch, _velMatchToAnchorWeight) // 5 ); return new PrioritySteering(1f, blended); }
public void CreateBehaviors() { Locomotion = new Locomotion(_context, _entity, _controllerData); VelocityMatch = new VelocityMatch(_context, _entity, _controllerData); Aim = new Aim(_context, _entity, _controllerData); }