// Start is called before the first frame update protected override void Start() { moveTypeSeek = new Seek(); moveTypeSeek.character = this; moveTypeSeek.target = target; moveTypeFlee = new Seek(); moveTypeFlee.flee = true; moveTypeFlee.character = this; moveTypeFlee.target = target; moveTypeEvade = new Evade(); moveTypeEvade.character = this; moveTypeEvade.target = target; moveTypeAvoid = new ObstacleAvoidance(); moveTypeAvoid.character = this; moveTypeAvoid.target = target; rotateTypeFace = new Face(); rotateTypeFace.character = this; rotateTypeFace.target = target; rotateTypeLWYG = new LookWhereYoureGoing(); rotateTypeLWYG.character = this; rotateTypeLWYG.target = target; }
//Function to create leader ships void CreateLeaders(Vector3 newpos) { GameObject leader = GameObject.Instantiate <GameObject> (prefab); leader.transform.parent = this.transform; leader.transform.position = this.transform.TransformPoint(newpos); leader.transform.rotation = this.transform.rotation; //add steering behaviours Wander w = leader.AddComponent <Wander>(); Seek seek = leader.AddComponent <Seek> (); seek.enabled = !seek.enabled; //disable seek behaviour ObstacleAvoidance obavd = leader.AddComponent <ObstacleAvoidance> (); //Change speed of boid Boid b = leader.GetComponent <Boid> (); b.maxSpeed = 2; //Create followers of leader for (int i = 1; i <= followers; i++) { Vector3 offset = new Vector3(gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); offset = new Vector3(-gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); } }
//void based steeringbehaviours public void ObstacleAvoidenceOn() { if (!behaviours.Contains(ObstacleAvoidance.GetInstance())) { behaviours.Add(ObstacleAvoidance.GetInstance()); } }
public static ObstacleAvoidance GetInstance() { if (instance == null) { instance = new ObstacleAvoidance(); } return(instance); }
void Start() { Separation separate = new Separation(); separate.character = this; GameObject[] goBirds = GameObject.FindGameObjectsWithTag("bird"); kBirds = new Kinematic[goBirds.Length - 1]; int j = 0; for (int i = 0; i < goBirds.Length - 1; i++) { if (goBirds[i] == this) { continue; } kBirds[j++] = goBirds[i].GetComponent <Kinematic>(); } separate.targets = kBirds; Arrive cohere = new Arrive(); cohere.character = this; cohere.target = myCohereTarget; LookWhereGoing myRotateType = new LookWhereGoing(); myRotateType.character = this; mySteering = new BlendedSteering(); mySteering.behaviors = new BehaviorAndWeight[3]; mySteering.behaviors[0] = new BehaviorAndWeight(); mySteering.behaviors[0].behavior = separate; mySteering.behaviors[0].weight = 1f; mySteering.behaviors[1] = new BehaviorAndWeight(); mySteering.behaviors[1].behavior = cohere; mySteering.behaviors[1].weight = 1f; mySteering.behaviors[2] = new BehaviorAndWeight(); mySteering.behaviors[2].behavior = myRotateType; mySteering.behaviors[2].weight = 1f; ObstacleAvoidance myAvoid = new ObstacleAvoidance(); myAvoid.character = this; myAvoid.target = myCohereTarget; myAvoid.flee = true; BlendedSteering myHighPrioritySteering = new BlendedSteering(); myHighPrioritySteering.behaviors = new BehaviorAndWeight[1]; myHighPrioritySteering.behaviors[0] = new BehaviorAndWeight(); myHighPrioritySteering.behaviors[0].behavior = myAvoid; myHighPrioritySteering.behaviors[0].weight = 1f; myAdvancedSteering = new PrioritySteering(); myAdvancedSteering.groups = new BlendedSteering[2]; myAdvancedSteering.groups[0] = new BlendedSteering(); myAdvancedSteering.groups[0] = myHighPrioritySteering; myAdvancedSteering.groups[1] = new BlendedSteering(); myAdvancedSteering.groups[1] = mySteering; }
// 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); }
void Start() { myMoveType = new ObstacleAvoidance(); myMoveType.character = this; myMoveType.target = myTarget; myRotateType = new LookWhereGoing(); myRotateType.character = this; myRotateType.target = myTarget; }
public Goblin(string name, Vector2D pos, World w, MovingEntity Target) : base(name, pos, w) { // State. hunting = new Hunting(this); retreating = new Retreating(this); guarding = new Guarding(this); wandering = new Wandering(this); regroup = new Regroup(this); obey = new Obeying(this); equip = new Equip(this); setState(guarding); // Starting state. FollowingOrder = false; Key = _lastKey + 1; _lastKey++; debugText = new List <string>(); this.Target = Target; Mass = 50; MaxSpeed = 5; MaxForce = 25; DamagePerAttack = 10; AttackRange = 10; AttackSpeed = 15; // Lower is faster. GroupValue = 10; NeighborsRange = 100; SeparationValue = 8; CohesionValue = 1; AlignmentValue = 16; FollowValue = 20; _SB = new ArrivalBehaviour(me: this, target: Target, slowingRadius: SlowingRadius); _FleeB = new FleeBehaviour(me: this, target: Target, panicDistance: PanicDistance); _FlockB = new FlockBehaviour(me: this, groupValue: GroupValue, cohesionValue: CohesionValue, alignmentValue: AlignmentValue, separationValue: SeparationValue); _LFB = new LeaderFollowingBehaviour(me: this, leader: Leader, slowingRadius: SlowingRadius, leaderBehindDist: 30, groupValue: GroupValue, followValue: FollowValue, separationValue: SeparationValue); _OA = new ObstacleAvoidance(this); _WA = new WallAvoidance(this); _WB = new WanderBehaviour(this, 100, 200); Velocity = new Vector2D(0, 0); SlowingRadius = 100; PanicDistance = 200; // Distance at which goblin starts fleeing. PassiveDistance = 1000; // Distance at which goblin goes to guard. BraveryDistance = 100; WanderRadius = 10; WanderDistance = 1; Scale = 4; VColor = Color.Black; AddDebugText("Current state: " + currentState, 0); AddDebugText("Previous state: " + previousState, 1); }
// Start is called before the first frame update void Start() { //DATOS DE PERSONAJE kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; //ARRIVE INITIALIZATION enemy = new GameObject();//creamos un enemigo ficticio que sera el mouse enemy.transform.position = Vector3.zero; kineticsEnemy = new Kinetics(0f, Vector3.zero, enemy.transform); arrive = new Arrive(kineticsAgent, kineticsEnemy, maxAccelerationArrive, agent.maxspeed, targetRadiusArrive, slowRadiusArrive, timeTotargetArrive); arrive.weigth = 1f; //AVOID INITIALIZATION obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); for (int i = 0; i < obstacles.Length; i++) { obs_trans.Add(obstacles[i].transform); } Transform[] obstacles_transforms = obs_trans.ToArray(); obstacleAvoidance = new ObstacleAvoidance(kineticsAgent, obstacles_transforms, avoidDistance, lookAheadAvoid, steeringAgent); obstacleAvoidance.weigth = 1f; //FACE INITIALIZATION face = new Face(kineticsAgent, kineticsEnemy); face.weigth = 1f; //BLEND INITIALIZATION behaviorsArrive[0] = arrive; behaviorsArrive[1] = face; behaviorsAvoid[0] = obstacleAvoidance; blendArrive = new BlendedSteering(behaviorsArrive, maxAccelBlend, maxAngularBlend); blendAvoid = new BlendedSteering(behaviorsAvoid, maxAccelBlend, maxAngularBlend); //PRIORITY INITIALIZATION groups[0] = blendAvoid;//OJO avoid tiene prioridad por eso va primero groups[1] = blendArrive; priority = new PrioritySteering(groups, steeringAgent); }
public MovingEntity(World world) { this.Mass = 30; this.MaxSpeed = .01f; this.MinSpeed = 1.0f; this.Velocity = new Vector2(); this.Orientation = new Vector2(1, 0); this.wallAvoidance = new WallAvoidance(this, world, 15f, 1.5f); this.obstacleAvoidance = new ObstacleAvoidance(this, world); }
protected virtual void Start() { InitOffset(); HP = MaxHP; PlayerGroup = Owner.Group; steerBh = Singleton.SteerBehavior; flockBh = Singleton.FlockBehavior; avoidanceBh = Singleton.ObstacleAvoidance; }
public virtual void Awake() { lineOfSight = GetComponent <LineOfSight>(); obstacleAvoidance = new ObstacleAvoidance(transform, obstacleAvoidRadius, obstacleAvoidWeight, obstacle); rb = GetComponent <Rigidbody>(); stopUpdate = true; manager = FindObjectOfType <GameManager>(); InitializeRouletteWheel(); }
private void Start() { sight = gameObject.GetComponent <LineOfSight>(); seek = gameObject.GetComponent <Seek>(); flee = gameObject.GetComponent <Flee>(); obstacleavoidance = gameObject.GetComponent <ObstacleAvoidance>(); //combat = gameObject.GetComponent<EnemyCombat>(); _enemy = gameObject.GetComponent <Enemy>(); timer = 0; CreateDecisionTree(); }
public static SteeringOutput GetSteering(KinematicState ownKS, SArrive arriveInfo, SObstacleAvoidance obstacleInfo, ref bool obstacleAvoided) { SteeringOutput obstacleAvoidSteering = ObstacleAvoidance.GetSteering(ownKS, obstacleInfo); if (obstacleAvoidSteering != NULL_STEERING) { obstacleAvoided = true; return(obstacleAvoidSteering); } obstacleAvoided = false; return(Arrive.GetSteering(ownKS, arriveInfo)); }
// Start is called before the first frame update protected virtual void Start() { arrive = new Arrive(); look = new LookWhereGoing(); seperate = new Seperation(); avoid = new ObstacleAvoidance(); flockGroups = new BlendedSteering[3]; arrive.target = target; arrive.ai = this; look.target = target; look.ai = this; seperate.ai = this; avoid.ai = this; AbstractKinematic[] kBirds; GameObject[] birds = GameObject.FindGameObjectsWithTag("Bird"); kBirds = new AbstractKinematic[birds.Length - 1]; int j = 0; for (int i = 0; i < birds.Length - 1; i++) { if (birds[i] == this) { continue; } kBirds[j++] = birds[i].GetComponent <AbstractKinematic>(); } seperate.targets = kBirds; InitializePriorityOne(); InitializePriorityTwo(); InitializePriorityThree(); /* * flocking.behaviors = new BehaviorAndWeight[3]; * BehaviorAndWeight behavior1 = new BehaviorAndWeight(); * behavior1.behavior = arrive; * behavior1.weight = 100f; * flocking.behaviors[0] = behavior1; * BehaviorAndWeight behavior2 = new BehaviorAndWeight(); * behavior2.behavior = look; * behavior2.weight = 1f; * flocking.behaviors[1] = behavior2; * BehaviorAndWeight behavior3 = new BehaviorAndWeight(); * behavior3.behavior = seperate; * behavior3.weight = 20f; * flocking.behaviors[2] = behavior3; */ }
// Start is called before the first frame update protected override void Start() { if (obstacle) { avoidTypeObs = new ObstacleAvoidance(); avoidTypeObs.character = this; avoidTypeObs.target = obstacleTarget; } else { avoidTypeCol = new CollisionAvoidance(); avoidTypeCol.character = this; avoidTypeCol.targets = avoidingTargets; } }
//Function to create leader void CreateLeaders(Vector3 newpos) { GameObject leader = GameObject.Instantiate <GameObject> (prefab); leader.transform.parent = this.transform; leader.transform.position = this.transform.TransformPoint(newpos); leader.transform.rotation = this.transform.rotation; //add steering behaviours Arrive arive = leader.AddComponent <Arrive> (); arive.targetPosition = leader.transform.position + leader.transform.forward * 100; //add target position to arrive there Seek seek = leader.AddComponent <Seek> (); seek.enabled = !seek.enabled; Path path = leader.AddComponent <Path> (); path.mothership = mothership; FollowPath fpath = leader.AddComponent <FollowPath> (); fpath.path = path; fpath.enabled = !fpath.enabled; ObstacleAvoidance obavd = leader.AddComponent <ObstacleAvoidance> (); obavd.enabled = !obavd.enabled; //Add boid and seek to the bombs(missiles) int count = leader.transform.Find("Bombs").gameObject.transform.childCount; for (int i = 0; i < count; i++) { Boid b = leader.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Boid> (); b.maxSpeed = 25f; b.explosionPrefab = expPrefab; Seek sb = leader.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Seek> (); sb.target = RandomTarget(); sb.enabled = !sb.enabled; } //Create followers for (int i = 1; i <= followers; i++) { Vector3 offset = new Vector3(gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); offset = new Vector3(-gap * i, 0, -gap * i); CreateFollower(offset, leader.GetComponent <Boid> ()); } }
// Start is called before the first frame update void Start() { //myMoveType = new Seek(); myMoveType = new ObstacleAvoidance(); myMoveType.character = this; myMoveType.target = myTarget; myMoveType.flee = flee; mySeekRotateType = new Face(); mySeekRotateType.character = this; mySeekRotateType.target = myTarget; myFleeRotateType = new LookWhereGoing(); myFleeRotateType.character = this; myFleeRotateType.target = myTarget; }
void Start() { obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); //Inicializamos las estructuras necesarias de otros componentes for (int i = 0; i < obstacles.Length; i++) { obs_trans.Add(obstacles[i].transform); } kineticsAgent = agent.kineticsAgent; steeringAgent = agent.steeringAgent; Transform[] obstacles_transforms = obs_trans.ToArray(); //Inicializamos movimientos obstacleAvoidance = new ObstacleAvoidance(kineticsAgent, obstacles_transforms, avoidDistance, lookAhead, steeringAgent); }
public override void SetWayPoints(List <Node> newPoints, Vector3 finalPos) { if (newPoints.Count == 0) { return; } _waypoints = newPoints; _finalPos = finalPos; _nextPoint = 0; var pos = _waypoints[_nextPoint].transform.position; pos.y = transform.position.y; _sb = new ObstacleAvoidance(transform, _waypoints[_nextPoint].transform, obstacleDistance, avoidWeight, avoidLayer); _lastConnection = false; }
/// <summary> /// Creates a new instance /// </summary> public Behaviors() { Alignment = new Alignment(); Arrive = new Arrive(); Cohesion = new Cohesion(); Evade = new Evade(); Flee = new Flee(); Hide = new Hide(); Interpose = new Interpose(); ObstacleAvoidance = new ObstacleAvoidance(); OffsetPursuit = new OffsetPursuit(); PathFollowing = new PathFollowing(); Pursuit = new Pursuit(); Seek = new Seek(); Separation = new Separation(); WallAvoidance = new WallAvoidance(); Wander = new Wander(); }
//Function to create followers void CreateFollower(Vector3 offset, Boid leader) { GameObject follower = GameObject.Instantiate <GameObject> (prefab); follower.transform.position = leader.transform.TransformPoint(offset); follower.transform.parent = this.transform; follower.transform.rotation = this.transform.rotation; //add steering behaviours Wander w = follower.AddComponent <Wander>(); Seek seek = follower.AddComponent <Seek> (); seek.enabled = !seek.enabled; ObstacleAvoidance obavd = follower.AddComponent <ObstacleAvoidance> (); Boid b = follower.GetComponent <Boid> (); b.maxSpeed = 2; }
//Could create the list here and use at the AI script aswell private void Awake() { //find mothership reference gameobject mothership = GameObject.Find("Mothership"); mshipsize = mothership.GetComponent <Collider> ().bounds.size; //get size of mothership.. use for making random missile target //create av8 leaders for (int i = 1; i <= leaders; i++) { Vector3 rndPos = new Vector3(Random.Range((-leaders * gapL), (leaders * gapL)), Random.Range((-leaders * gapL), (leaders * gapL)), 0); CreateLeaders(rndPos); } //Create K.Russel plane.. use for last scene GameObject leader = GameObject.Instantiate <GameObject> (krprefab); leader.transform.position = this.transform.TransformPoint(new Vector3(0, -50, 0)); leader.transform.rotation = this.transform.rotation; //add steering behaviours //Follows a static path gameobject FollowPath fpath = leader.AddComponent <FollowPath> (); fpath.path = GameObject.Find("KRpath").GetComponent <Path>(); fpath.enabled = fpath.enabled; ObstacleAvoidance obavd = leader.AddComponent <ObstacleAvoidance> (); leader.GetComponent <Boid> ().maxSpeed = 30; // float thetaInc = (Mathf.PI * 2) / leaders; // for (int i = 1; i <= leaders; i++) { // // float theta = thetaInc * i; // Vector3 newpos = new Vector3 (Mathf.Sin (theta) * gapL, 0, Mathf.Cos (theta) * gapL); // Debug.Log (newpos); // CreateLeaders (newpos); // } // for (int i = 1; i <=leaders; i++) // { // Vector3 offset = new Vector3(- gapL, 0, 0); // gapL += gapL; // CreateLeaders(offset); // } }
public Hobgoblin(string name, Vector2D pos, World w, MovingEntity Target) : base(name, pos, w) { // State. hunting = new Hunting(this); retreating = new Retreating(this); guarding = new Guarding(this); wandering = new Wandering(this); command = new Command(this); equip = new Equip(this); setState(guarding); // Starting state. Key = _lastKey + 1; _lastKey++; debugText = new List <string>(); Mass = 100; MaxSpeed = 5; MaxForce = 40; DamagePerAttack = 25; AttackRange = 20; AttackSpeed = 30; // Lower is faster. CurrentCommand = 3; // Default command. CommandRadius = 125; // Size of area where goblins will respond to commanding. SlowingRadius = 100; PanicDistance = 200; // Distance at which hobgoblin starts fleeing. PassiveDistance = 250; // Distance at which hobgoblin goes to guard. _SB = new ArrivalBehaviour(me: this, target: Target, slowingRadius: SlowingRadius); _FleeB = new FleeBehaviour(me: this, target: Target, panicDistance: PanicDistance); _OA = new ObstacleAvoidance(this); _WA = new WallAvoidance(this); _WB = new WanderBehaviour(this, 100, 200); Velocity = new Vector2D(0, 0); SlowingRadius = 100; Scale = 10; VColor = Color.Black; AddDebugText("Current state: " + currentState, 0); AddDebugText("Previous state: " + previousState, 1); }
//Method to create Follwers void CreateFollower(Vector3 offset, Boid leader) { GameObject follower = GameObject.Instantiate <GameObject> (prefab); follower.transform.position = leader.transform.TransformPoint(offset); follower.transform.parent = this.transform; follower.transform.rotation = this.transform.rotation; follower.name = "follower"; //add steering behaviours OffsetPursue op = follower.AddComponent <OffsetPursue> (); op.leader = leader; Seek seek = follower.AddComponent <Seek> (); seek.enabled = !seek.enabled; Path path = follower.AddComponent <Path> (); path.mothership = mothership; FollowPath fpath = follower.AddComponent <FollowPath> (); fpath.path = path; fpath.enabled = !fpath.enabled; ObstacleAvoidance obavd = follower.AddComponent <ObstacleAvoidance> (); obavd.enabled = !obavd.enabled; //Add boid and seek to the bombs(missiles) int count = follower.transform.Find("Bombs").gameObject.transform.childCount; for (int i = 0; i < count; i++) { Boid b = follower.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Boid> (); b.maxSpeed = 25f; b.explosionPrefab = expPrefab; Seek sb = follower.transform.Find("Bombs").GetChild(i).gameObject.AddComponent <Seek> (); sb.target = RandomTarget(); sb.enabled = !sb.enabled; } }
public override void Run() { var point = _waypoints[_nextPoint]; var posPoint = point.transform.position; posPoint.y = transform.position.y; Vector3 dir; if (!_lastConnection) { dir = posPoint - transform.position; } else { dir = _finalPos - transform.position; } if (dir.magnitude < nextWaypointDistance) { if (!_lastConnection) { if (_nextPoint + 1 < _waypoints.Count) { _nextPoint++; _sb = new ObstacleAvoidance(transform, _waypoints[_nextPoint].transform, obstacleDistance, avoidWeight, avoidLayer); } else if (_nextPoint + 1 >= _waypoints.Count) { _lastConnection = true; _sb = new ObstacleAvoidance(transform, _finalPos, obstacleDistance, avoidWeight, avoidLayer); } } } _model.Move(dir.normalized + _sb.GetDir()); }
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); }
void Start() { myMoveType = new ObstacleAvoidance(); myMoveType.character = this; myMoveType.target = myTarget; }
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); }
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); }
Steering getDefaultSteering(Entry e, FormationManager generalManager, Flock flock) { var pattSteering = new PatternSteering(e.bird, generalManager); var separation = new Separation(e.bird, flock, 5.0f, -1f); separation.aknnApproxVal = 1.0; var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"}); 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(pattSteering, 1f)); return new PrioritySteering(1f, blended); }
void Awake() { _groundDetection = GetComponent <GroundDetection>(); _obstacleAvoidance = GetComponent <ObstacleAvoidance>(); }
// Update is called once per frame void Update() { //Debug.Log(target); // Check distance to see if steering behavior should be applied to AI // float targetDist = (transform.position - target.transform.position).magnitude; // if (!DistanceActivation || targetDist >= activationRange) { } transform.position += linearVelocity * Time.deltaTime; // adding angular velocity to current transform rotation y component if (float.IsNaN(angularVelocity)) { angularVelocity = 0; } transform.eulerAngles += new Vector3(0, angularVelocity * Time.deltaTime, 0); // control to switch to proper steering behavior if (avoidObstacles) { ObstacleAvoidance avoid = new ObstacleAvoidance(); avoid.ai = this; SteeringOutput avoidForce = avoid.GetSteering(); if (avoidForce != null) { linearVelocity += avoidForce.linear; } } if (seperationObstacles.Length > 0) { Seperation seperation = new Seperation(); seperation.targets = seperationObstacles; seperation.ai = this; SteeringOutput seperateForce = seperation.GetSteering(); // check to see if steering is greater than zero and lock out control from other steering if (seperateForce.linear.magnitude > 0) { seperating = true; } else { seperating = false; } linearVelocity += seperateForce.linear * Time.deltaTime; } if (collisionAvoidance.Length > 0) { CollisionAvoidance avoidKinematic = new CollisionAvoidance(); avoidKinematic.ai = this; avoidKinematic.targets = collisionAvoidance; SteeringOutput avoidKinematicForce = avoidKinematic.GetSteering(); if (avoidKinematicForce != null) { linearVelocity += avoidKinematicForce.linear; } } switch (movementType) { case "seek": Seek mySeek = new Seek(); mySeek.ai = this; // if seek is false set seek property on class to false to activate flee mySeek.seek = true; mySeek.target = target; SteeringOutput steeringSeek = mySeek.GetSteering(); if (!seperating) { linearVelocity += steeringSeek.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "flee": Seek myFlee = new Seek(); myFlee.ai = this; // if seek is false set seek property on class to false to activate flee myFlee.seek = false; myFlee.target = target; SteeringOutput steeringFlee = myFlee.GetSteering(); if (!seperating) { linearVelocity += steeringFlee.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "arrive": Arrive myArrive = new Arrive(); myArrive.ai = this; myArrive.target = target; SteeringOutput steeringArrive = myArrive.GetSteering(); if (!seperating) { linearVelocity += steeringArrive.linear * Time.deltaTime; } break; case "pursue": Pursue myPursue = new Pursue(); myPursue.ai = this; myPursue.target = target; SteeringOutput steeringPursue = myPursue.GetSteering(); if (!seperating) { linearVelocity += steeringPursue.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; case "evade": Pursue myEvade = new Pursue(); myEvade.ai = this; myEvade.target = target; // This changes the seek flag in the parent Seek class of Pursue, sending it the flee vector instead myEvade.seek = false; SteeringOutput steeringEvade = myEvade.GetSteering(); if (!seperating) { linearVelocity += steeringEvade.linear * Time.deltaTime; } if (linearVelocity.magnitude > maxSpeed) { linearVelocity.Normalize(); linearVelocity *= maxSpeed; } break; default: // provide no input break; // If obstacles have been provided, return steering to seperate from them } switch (rotationType) { case "face": Face myFace = new Face(); myFace.ai = this; myFace.target = target; SteeringOutput steeringFace = myFace.GetSteering(); if (steeringFace != null) { // linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringFace.angular * Time.deltaTime; } break; case "align": Align myAlign = new Align(); myAlign.ai = this; myAlign.target = target; SteeringOutput steeringAlign = myAlign.GetSteering(); if (steeringAlign != null) { //linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringAlign.angular * Time.deltaTime; } break; case "look": LookWhereGoing myLook = new LookWhereGoing(); myLook.ai = this; myLook.target = target; SteeringOutput steeringLook = myLook.GetSteering(); if (steeringLook != null) { //linearVelocity += steering.linear * Time.deltaTime; angularVelocity += steeringLook.angular * Time.deltaTime; } break; default: //provide no input break; } }
void MainSteeringBehaviors() { ResetOrientation(); switch (choiceOfBehavior) { case SteeringBehaviors.Seek: Seek seek = new Seek(); seek.character = this; seek.target = newTarget; SteeringOutput seeking = seek.getSteering(); if (seeking != null) { linear += seeking.linear * Time.deltaTime; angular += seeking.angular * Time.deltaTime; } break; case SteeringBehaviors.Flee: Flee flee = new Flee(); flee.character = this; flee.target = newTarget; SteeringOutput fleeing = flee.getSteering(); if (fleeing != null) { linear += fleeing.linear * Time.deltaTime; angular += fleeing.angular * Time.deltaTime; } break; case SteeringBehaviors.Align: Align align = new Align(); align.character = this; align.target = newTarget; SteeringOutput aligning = align.getSteering(); if (aligning != null) { linear += aligning.linear * Time.deltaTime; angular += aligning.angular * Time.deltaTime; } break; case SteeringBehaviors.Face: Face face = new Face(); face.character = this; face.target = newTarget; SteeringOutput facing = face.getSteering(); if (facing != null) { linear += facing.linear * Time.deltaTime; angular += facing.angular * Time.deltaTime; } break; case SteeringBehaviors.LookWhereGoing: LookWhereGoing look = new LookWhereGoing(); look.character = this; look.target = newTarget; SteeringOutput looking = look.getSteering(); if (looking != null) { linear += looking.linear * Time.deltaTime; angular += looking.angular * Time.deltaTime; } break; case SteeringBehaviors.Arrive: Arrive arrive = new Arrive(); arrive.character = this; arrive.target = newTarget; SteeringOutput arriving = arrive.getSteering(); if (arriving != null) { linear += arriving.linear * Time.deltaTime; angular += arriving.angular * Time.deltaTime; } break; case SteeringBehaviors.PathFollow: follow.character = this; lookwg.character = this; follow.path = myPath; lookwg.target = newTarget; SteeringOutput following = follow.getSteering(); SteeringOutput lookingwg = lookwg.getSteering(); if (following != null) { linear += following.linear * Time.deltaTime; // angular += lookingwg.angular* Time.deltaTime; } break; case SteeringBehaviors.Pursue: Pursue pursue = new Pursue(); LookWhereGoing PursuelookWhereGoing = new LookWhereGoing(); pursue.character = this; PursuelookWhereGoing.character = this; pursue.target = newTarget; PursuelookWhereGoing.target = newTarget; SteeringOutput pursuing = pursue.getSteering(); SteeringOutput pursuelookingWhereGoing = PursuelookWhereGoing.getSteering(); if (pursuing != null) { if (pursuing.linear.magnitude <= maxSpeed) { linear += pursuing.linear * Time.deltaTime; } angular += pursuing.angular * Time.deltaTime; } break; case SteeringBehaviors.Separate: Separation separate = new Separation(); LookWhereGoing lookWhereGoing = new LookWhereGoing(); separate.character = this; lookWhereGoing.character = this; separate.targets = targets; lookWhereGoing.target = newTarget; SteeringOutput lookingWhereGoing = lookWhereGoing.getSteering(); SteeringOutput separating = separate.getSteering(); if (separating != null) { linear += separating.linear * Time.deltaTime; angular += separating.angular * Time.deltaTime; } break; case SteeringBehaviors.CollisionAvoidance: CollisionAvoidance avoid = new CollisionAvoidance(); LookWhereGoing AvoidlookWhereGoing = new LookWhereGoing(); avoid.character = this; AvoidlookWhereGoing.character = this; avoid.targets = targets; AvoidlookWhereGoing.target = newTarget; SteeringOutput AvoidlookingWhereGoing = AvoidlookWhereGoing.getSteering(); SteeringOutput avoiding = avoid.getSteering(); if (avoiding != null) { linear += avoiding.linear * Time.deltaTime; angular += avoiding.angular * Time.deltaTime; } break; case SteeringBehaviors.ObstacleAvoidance: ObstacleAvoidance obAvoid = new ObstacleAvoidance(); LookWhereGoing obAvoidlookWhereGoing = new LookWhereGoing(); obAvoid.character = this; obAvoidlookWhereGoing.character = this; obAvoid.target = newTarget; obAvoidlookWhereGoing.target = newTarget; SteeringOutput obAvoiding = obAvoid.getSteering(); SteeringOutput obAvoidlookingWhereGoing = obAvoidlookWhereGoing.getSteering(); if (obAvoiding != null) { if (obAvoiding.linear.magnitude <= maxSpeed) { linear += obAvoiding.linear * Time.deltaTime; } angular += obAvoiding.angular * Time.deltaTime; } break; case SteeringBehaviors.Flocking: Separation sepFlock = new Separation(); Arrive arriveFlock = new Arrive(); LookWhereGoing lwgFlock = new LookWhereGoing(); BlendedSteering mySteering = new BlendedSteering(); Kinematic[] kBirds; sepFlock.character = this; GameObject[] goBirds = GameObject.FindGameObjectsWithTag("Pengu"); kBirds = new Kinematic[goBirds.Length - 1]; int j = 0; for (int i = 0; i < goBirds.Length - 1; i++) { if (goBirds[i] == this) { continue; } goBirds[i].GetComponent <Animator>().SetInteger("Walk", 1); kBirds[j++] = goBirds[i].GetComponent <Kinematic>(); } sepFlock.targets = kBirds; arriveFlock.character = this; //Debug.Log(arriveFlock.character); arriveFlock.target = newTarget; //Debug.Log(arriveFlock.target); lwgFlock.character = this; lwgFlock.target = newTarget; mySteering.behaviors = new BehaviorAndWeight[3]; mySteering.behaviors[0] = new BehaviorAndWeight(); mySteering.behaviors[0].behavior = sepFlock; mySteering.behaviors[0].weight = 1f; mySteering.behaviors[1] = new BehaviorAndWeight(); mySteering.behaviors[1].behavior = arriveFlock; mySteering.behaviors[1].weight = 1f; mySteering.behaviors[2] = new BehaviorAndWeight(); mySteering.behaviors[2].behavior = lwgFlock; mySteering.behaviors[2].weight = 1f; ObstacleAvoidance myAvoid = new ObstacleAvoidance(); myAvoid.character = this; myAvoid.target = newTarget; myAvoid.flee = true; BlendedSteering myHighPrioritySteering = new BlendedSteering(); myHighPrioritySteering.behaviors = new BehaviorAndWeight[1]; myHighPrioritySteering.behaviors[0] = new BehaviorAndWeight(); myHighPrioritySteering.behaviors[0].behavior = myAvoid; myHighPrioritySteering.behaviors[0].weight = 0.1f; myAdvancedSteering.groups = new BlendedSteering[2]; myAdvancedSteering.groups[0] = new BlendedSteering(); myAdvancedSteering.groups[0] = myHighPrioritySteering; myAdvancedSteering.groups[1] = new BlendedSteering(); myAdvancedSteering.groups[1] = mySteering; //steeringUpdate = mySteering.getSteering(); avoidObstacles = true; if (!avoidObstacles) { steeringUpdate = mySteering.getSteering(); if (steeringUpdate != null) { linear += steeringUpdate.linear * Time.deltaTime; angular += steeringUpdate.angular * Time.deltaTime; } } else { steeringUpdate = myAdvancedSteering.getSteering(); if (steeringUpdate != null) { linear += steeringUpdate.linear * Time.deltaTime; angular += steeringUpdate.angular * Time.deltaTime; } } break; case SteeringBehaviors.PathFinder: SteeringOutput lwyger = myRotateType.getSteering(); linear += myMoveType.getSteering().linear *Time.deltaTime; angular += myMoveType.getSteering().angular *Time.deltaTime; break; } }