// Use this for initialization void Start() { restingTimer = restingTime; timer = transitionTimer; agent = GetComponent <NavMeshAgent>(); wander = GetComponent <WanderBehaviour>(); seek = GetComponent <SeekBehaviour>(); flee = GetComponent <Flee>(); }
// Use this for initialization void Start() { agent = GetComponent <NavMeshAgent>(); wonder = GetComponent <WanderBehaviour>(); currentHunger = maxHunger; currentEnergy = maxEnergy; currentLife = maxLife; timer = eventChangeTimer; }
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); }
public FlockingBehaviour(MovingEntity entity, World world, float radius, float alignmentWeight = 6, float cohesionWeight = 16, float separationWeight = 16) : base(entity) { this.world = world; this.alignmentRadius = radius; this.cohesionRadius = radius; this.separationRadius = radius; this.alignmentWeight = alignmentWeight; this.cohesionWeight = cohesionWeight; this.separationWeight = separationWeight; this.innerWander = new WanderBehaviour(entity, radius); }
public override void setupScene() { Random rand = new Random(System.DateTime.Now.Millisecond); Tank t; for (int i = 0; i < 5; i++) { MeinGun g = new MeinGun(); g.transform.position += new Vector2(2, 5); t = new Tank(new Vector2(rand.Next(0, 800), rand.Next(0, 600)), uManager.CManager.Load <Texture2D>("Tank//OrangeTank"), 100, g); WanderBehaviour w = new WanderBehaviour(i * 10); w.Parent = t; t.addBehaviour("wanderBehaviour", w); this.addChild(t); } }
public FindFoodState(EntityStateMachine ownerFiniteStateMachine) : base(ownerFiniteStateMachine) { SeekBehaviour seekBehaviour = new SeekBehaviour(OwnerEntity.SeekTarget, OwnerEntity); wanderBehaviour = new WanderBehaviour(OwnerEntity); steeringBehaviours.Add(seekBehaviour); steeringBehaviours.Add(new DistancingBehaviour(OwnerEntity)); steeringBehaviours.Add(new ObstacleAvoidance(OwnerEntity)); Name = "FindFood"; // If the entity doesn't have a target for some reason, try to find one if (OwnerEntity.SeekTarget == null) { // try to find new target seekBehaviour.NewTarget(OwnerEntity.SeekTarget); // If it's still Null, no targets exist } }
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); }
private BaseState GetBehaviour(AIBehaviour behaviour) { BaseState retVal = null; switch (behaviour) { case AIBehaviour.Patrolling: retVal = new PatrolBehaviour(this); break; case AIBehaviour.Wander: retVal = new WanderBehaviour(this); break; case AIBehaviour.Skirmish: retVal = new SkirmishBehaviour(this); break; case AIBehaviour.ChargeTarget: retVal = new BerserkerBehaviour(this); break; case AIBehaviour.Cover: retVal = new TacticalBehaviour(this); break; case AIBehaviour.MoveToTransform: retVal = new MoveToTransformBehaviour(this); break; case AIBehaviour.Chase: retVal = new ChaseState(this); break; default: throw new ArgumentOutOfRangeException(nameof(behaviour), behaviour, null); } retVal.Enter(); return(retVal); }
void Start() { // PickableUpObject PickedUp = false; disposed = false; wander = GetComponent <WanderBehaviour>(); seek = GetComponent <SeekBehaviour>(); avoid = GetComponent <AvoidBehaviour>(); steering = GetComponent <DelegatedSteering>(); behaviour = new RobotBehaviour(this); board = UnityEngine.Object.FindObjectsOfType <BlackBoard>()[0]; CurrentBattery = FullBattery; CurrentTrash = null; PickedUpObject = null; behaviour.Start(); }
/// <summary> /// Constructor for wander behaviour. /// </summary> /// <param name="behaviour"> /// Details for this behaviour. /// </param> /// <param name="parentBehaviour"> /// Reference to component to decorate. /// </param> public WanderBehaviourDecorator(AbstractBehaviourComponent parentBehaviour, MovementBehaviour behaviour) : base(parentBehaviour, behaviour) { this.behaviour = behaviour as WanderBehaviour; }
public TankPatrol(Tank tank) { wanderBehaviour = new WanderBehaviour(210, 250, 50); TimeElapsed = GlobalVars.BehaviourDelay; steeringForce = new Vector(2, 2); }
private IBehaviour CreateBunnyAI() { Selector mainSelector = new Selector("Main Selector") .Add( idleDesire ); //mainSelector.children.AddRange(new IBehaviour[] { idleDesire, eatFoodDesire, avoidDangerDesire, attackHatedDecider }); // Idle subtree. Selector idleSelector = new Selector("Idle Selector"); // Idle -> Wander tree TreeInternalNode wanderSequencer = new Sequencer("Wander Behaviour"); IBehaviour findWanderTarget = new WanderBehaviour("Find Wander Target"); IBehaviour moveToPosition = new WalkToBehaviour("Walk to target"); wanderSequencer.children.Add(findWanderTarget); wanderSequencer.children.Add(moveToPosition); Repeater wanderRepeater = new Repeater(); wanderRepeater.child = wanderSequencer; AnonUtilityWrapper wanderDesire = new AnonUtilityWrapper(); wanderDesire.child = wanderSequencer; wanderDesire.utilityFunction = (x) => { return(0.5f); }; // Idle -> Breed Tree. IBehaviour findMateBehaviour = new PickSameSpecies("Find a mate"); IBehaviour walkToMateBehaviour = new WalkToTarget("Walk to the mate"); IBehaviour breedBehaviour = new Breed(""); Sequencer breedSequencer = new Sequencer("Breeding"); breedSequencer.children.AddRange(new IBehaviour[] { findMateBehaviour, walkToMateBehaviour, breedBehaviour }); AnonUtilityWrapper breedDesire = new AnonUtilityWrapper(); breedDesire.child = breedSequencer; breedDesire.utilityFunction = (x) => { return(x.target.BreedDesire()); }; idleSelector.children.AddRange(new IBehaviour[] { wanderDesire, breedDesire }); AnonUtilityWrapper idleDesire = new AnonUtilityWrapper(); idleDesire.child = idleSelector; idleDesire.utilityFunction = (x) => { return(0.5f); }; // Find and eat food subtree. TreeInternalNode findFoodSubtree = new Sequencer("Find Food Subtree"); IBehaviour findFood = new FindFood("Find Food"); IBehaviour walkToFood = new WalkToTarget("Walk To Food"); IBehaviour eat = new Eat("Eat Food"); findFoodSubtree.children.AddRange(new IBehaviour[] { findFood, walkToFood, eat }); AnonUtilityWrapper eatFoodDesire = new AnonUtilityWrapper("Desire for food."); eatFoodDesire.child = findFoodSubtree; eatFoodDesire.utilityFunction = (x) => { if (x == null || x.target == null) { return(0f); } if (x.target.eating) { return(1f); } else { return((x.target.hunger - 15f) / 15f); } }; // Flee Danger Subtree Repeater avoidTreeRepeater = new Repeater(); Sequencer avoidDangerTree = new Sequencer("Running Away Subtree"); avoidTreeRepeater.child = avoidDangerTree; IBehaviour avoidDanger = new AvoidDanger("Work out where to run"); IBehaviour walkAway = new WalkToBehaviour("Do the running away"); avoidDangerTree.children.AddRange(new IBehaviour[] { avoidDanger, walkAway }); AnonUtilityWrapper avoidDangerDesire = new AnonUtilityWrapper("Current danger estimate"); avoidDangerDesire.SetChild(avoidTreeRepeater); avoidDangerDesire.utilityFunction = (x) => { if (x.target.predator) { return(0f); } if (x.target.hunter == null) { return(0f); } else { float distance = (x.target.hunter.transform.position - x.target.transform.position).magnitude; if (distance < 8f) { return((8f - distance) / 3f); } else { return(0f); } } }; // Attack Hated behaviours. FindHatedTarget findTarget = new FindHatedTarget(""); WalkToTarget moveToTarget = new WalkToTarget("Approach victim"); Attack attackTarget = new Attack(); Sequencer attackHatedSequencer = new Sequencer("Attack Hated Creatures"); attackHatedSequencer.children.AddRange(new IBehaviour[] { findTarget, moveToTarget, attackTarget }); AnonUtilityWrapper attackHatedDecider = new AnonUtilityWrapper("Impact of nearby hated units"); attackHatedDecider.SetChild(attackHatedSequencer); attackHatedDecider.utilityFunction = (x) => { return(findTarget.GetUtility()); }; mainSelector.children.AddRange(new IBehaviour[] { idleDesire, eatFoodDesire, avoidDangerDesire, attackHatedDecider }); Repeater repeatAll = new Repeater(); repeatAll.SetChild(mainSelector); return(repeatAll); }
void Start () { #if (UNITY_EDITOR) if(!EditorApplication.isPlaying) { } else { #endif var go = this.gameObject; ApexComponentMaster master; Rigidbody rb; //Add the required components /* go.AddIfMissing<Rigidbody>(go, false, out rb); bool toggleAll = go.AddIfMissing<ApexComponentMaster>(false, out master); go.AddIfMissing<HumanoidSpeedComponent>(false); go.AddIfMissing<UnitComponent>(false); go.AddIfMissing<SteerableUnitComponent>(go, false); go.AddIfMissing<DefaultHeightNavigator>(go, false); go.AddIfMissing<PathOptionsComponent>(go, false); go.AddIfMissing<SteerToAlignWithVelocity>(go, false); go.AddIfMissing<SteerForPathComponent>(go, 5); go.AddIfMissing<PathVisualizer>(go, false); */ Rigidbody r; this.gameObject.AddIfMissing<Rigidbody>(out r); ApexComponentMaster apexM; HumanoidSpeedComponent hsc; PathOptionsComponent poc; UnitComponent uni; SteerToAlignWithVelocity steer; SteerForPathComponent sfp; WanderBehaviour wand; DefaultHeightNavigator dfn; SteerableUnitComponent suc; SpeedComponent sc; this.gameObject.AddIfMissing<ApexComponentMaster>(out apexM); this.gameObject.AddIfMissing<HumanoidSpeedComponent>(out hsc); this.gameObject.AddIfMissing<UnitComponent>(out uni); this.gameObject.AddIfMissing<SteerForPathComponent>(out sfp); this.gameObject.AddIfMissing<SteerableUnitComponent>(out suc); this.gameObject.AddIfMissing<DefaultHeightNavigator>(out dfn); this.gameObject.AddIfMissing<PathOptionsComponent>(out poc); this.gameObject.AddIfMissing<SteerToAlignWithVelocity>(out steer); this.gameObject.AddIfMissing<SpeedComponent>(out sc); apexMain = this.GetComponent<IMovingObject> (); if(apexMain==null) { apexMain = gameObject.AddComponent<SteerableUnitComponent>(); } apexM.ToggleAll(); unit = this.GetUnitFacade (true); this.gameObject.AddIfMissing<WanderBehaviour>(out wand); anim = this.GetComponentInChildren<Animator> (); steerable = (SteerableUnitComponent) apexMain; suc.enabled = true; sc.enabled = true; uni.enabled = true; poc.enabled = true; dfn.enabled = true; sfp.enabled = true; steer.enabled = true; apexM.enabled = true; BattleMonster m = this.GetComponentInChildren<BattleMonster> (); if (m != null) { Destroy (m); } #if (UNITY_EDITOR) } #endif player = GameObject.FindGameObjectWithTag ("Player"); wander = GetComponent<WanderBehaviour> (); StartCoroutine(toggleOnOffRootMotion()); }
public void WanderOff() { _wander = null; _dWander = 0; }
public void WanderOn(double intensity) { _wander = new WanderBehaviour(_movingEntity); _dWander = intensity; }