コード例 #1
0
    /// <summary>
    /// function called when the obj is created by the MooseManager in order to set all variables
    /// </summary>
    /// <param name="_cohW"></param>
    /// <param name="_sepW"></param>
    /// <param name="_aliW"></param>
    /// <param name="_sibW"></param>
    public void StartBehaviours(Bounds _movingBounds, float _padding, GameObject _predator)
    {
        cohesionInternal             = GetComponent <Cohesion>();
        cohesionInternal.weight      = coehVal.x;
        separationInternal           = GetComponent <Separation>();
        separationInternal.weight    = separVal.x;
        alignmentInternal            = GetComponent <Alignment>();
        alignmentInternal.weight     = aligVal.x;
        stayInBoundsInternal         = GetComponent <StayInBounds>();
        stayInBoundsInternal.weight  = stayInBVal.x;
        stayInBoundsInternal.bounds  = _movingBounds;
        stayInBoundsInternal.padding = _padding;
        constantSpeedInternal        = GetComponent <ConstantSpeed>();
        constantSpeedInternal.speed  = speed.x;
        fleeInternal        = GetComponent <Flee>();
        fleeInternal.evader = _predator.GetComponent <Vehicle>();



        GetComponent <Vehicle>().behaviours.Add(cohesionInternal);
        GetComponent <Vehicle>().behaviours.Add(separationInternal);
        GetComponent <Vehicle>().behaviours.Add(alignmentInternal);
        GetComponent <Vehicle>().behaviours.Add(stayInBoundsInternal);
        GetComponent <Vehicle>().behaviours.Add(constantSpeedInternal);
        GetComponent <Vehicle>().behaviours.Add(fleeInternal);

        fsm = GetComponent <FSM>();
        fsm.LoadState <FSMMooseWander>();
        fsm.LoadState <FSMMooseCauntion>();
        fsm.LoadState <FSMMooseRun>();
        fsm.ActivateState <FSMMooseWander>();
    }
コード例 #2
0
 public void CohesionOn()
 {
     if (!behaviours.Contains(Cohesion.GetInstance()))
     {
         behaviours.Add(Cohesion.GetInstance());
     }
 }
コード例 #3
0
 public static Cohesion GetInstance()
 {
     if (instance == null)
     {
         instance = new Cohesion();
     }
     return(instance);
 }
コード例 #4
0
ファイル: Flock.cs プロジェクト: gilReyes/ReefCube
 // Use this for initialization
 void Start()
 {
     cohesion       = new Cohesion(this.gameObject, m_MaxAcceletaion, m_TargetRadius, m_SlowRadius, m_TimeToTarget);
     align          = new Align(this.gameObject, m_TurnSpeed);
     flockingOutput = new SteeringOutput();
     m_transitions  = new Transition[2];
     InitializeTransitions();
 }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: Loxon1282/OctopusGame
    void Awake( )
    {
        _boids      = new List <Boid>( );
        _alignment  = new Alignment( );
        _cohesion   = new Cohesion( );
        _separation = new Separation( );

        extractXmlValues(readDataStorageXml("dataStorage.xml"));
        //get the values of the flocking rules from the uiManager.
    }
コード例 #6
0
ファイル: Flocking.cs プロジェクト: fylux/GameAI
    //OJO! En el steering que sea que vaya a llamar de forma estática a esta función, se deberán ejecutar las dos siguientes lineas
    //   wanderOrientation += Flocking.UpdateWanderOrientation(wanderOrientation, wanderRate)
    //   wanderForce = Wander.GetSteering(npc, wanderForce, wanderCooldown, wanderRate, wanderOrientation, wanderCircleOffset, wanderCircleRadius, maxAccel, timeToTarget, visibleRays)
    //  Es por eso que trabajar con flocking de manera estática está desaconsejado
    public static Steering GetSteering(Agent npc, float groupArea, float decayCoefficient, float maxAccel, bool visibleRays, float timeToTarget, float wanderCooldown, float wanderRate, float wanderOrientation, float wanderCircleOffset, float wanderCircleRadius, Steering wanderForce, float cohesionPriority, float separationPriority, float alignmentPriority, float wanderPriority)
    {
        Steering steering = new Steering();

        steering.linear += Separation.GetSteering(npc, groupArea, decayCoefficient, maxAccel, visibleRays).linear *separationPriority;
        steering.linear += Cohesion.GetSteering(npc, groupArea, decayCoefficient, maxAccel, visibleRays).linear *cohesionPriority;
        steering.angular = Alignment.GetSteering(npc, groupArea, npc.interiorAngle, npc.exteriorAngle, timeToTarget, false).angular *alignmentPriority;
        steering        += Steering.ApplyPriority(wanderForce, wanderPriority);
        return(steering);
    }
コード例 #7
0
    // 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>();
    }
コード例 #8
0
 void Awake()
 {
     boids      = new List <Boid>();
     alignment  = new Alignment();
     cohesion   = new Cohesion();
     separation = new Separation();
     waypoint   = new FollowWaypoints();
     eatFood    = new EatFood();
     flee       = new Flee();
 }
コード例 #9
0
    // 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>();
    }
コード例 #10
0
    // Start is called before the first frame update
    void Start()
    {
        agentScript          = gameObject.AddComponent <Agent>();
        agentScript.maxSpeed = maxSpeed;

        cohesionScript           = gameObject.AddComponent <Cohesion>();
        seperationScript         = gameObject.AddComponent <Seperation>();
        cohesionScript.targets   = target.GetComponent <SquadLeader>().children;
        seperationScript.targets = cohesionScript.targets;

        ChangeState(UnitStates.Seek);
    }
コード例 #11
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = AbovePhreaticLevel.GetHashCode();
         hashCode = (hashCode * 397) ^ BelowPhreaticLevel.GetHashCode();
         hashCode = (hashCode * 397) ^ Cohesion.GetHashCode();
         hashCode = (hashCode * 397) ^ FrictionAngle.GetHashCode();
         hashCode = (hashCode * 397) ^ ShearStrengthRatio.GetHashCode();
         hashCode = (hashCode * 397) ^ StrengthIncreaseExponent.GetHashCode();
         hashCode = (hashCode * 397) ^ Pop.GetHashCode();
         return(hashCode);
     }
 }
コード例 #12
0
 private bool Equals(MacroStabilityInwardsSoilLayerData other)
 {
     return(string.Equals(materialName, other.materialName, StringComparison.InvariantCulture) &&
            IsAquifer == other.IsAquifer &&
            Color.ToArgb().Equals(other.Color.ToArgb()) &&
            UsePop == other.UsePop &&
            ShearStrengthModel == other.ShearStrengthModel &&
            AbovePhreaticLevel.Equals(other.AbovePhreaticLevel) &&
            BelowPhreaticLevel.Equals(other.BelowPhreaticLevel) &&
            Cohesion.Equals(other.Cohesion) &&
            FrictionAngle.Equals(other.FrictionAngle) &&
            ShearStrengthRatio.Equals(other.ShearStrengthRatio) &&
            StrengthIncreaseExponent.Equals(other.StrengthIncreaseExponent) &&
            Pop.Equals(other.Pop));
 }
コード例 #13
0
 public override IEnumerator Enter(Machine owner, Brain controller)
 {
     mainMachine = owner;
     myBrain = controller;
     Legs myLegs = myBrain.legs;
     cohesion = new Cohesion(controller.allObjects);
     cohesion.setWeight (0.3f);
     cohesion.Init (myLegs);
     alignment = new Alignment(controller.allObjects);
     alignment.Init (myLegs);
     alignment.setWeight(0.2f);
     myLegs.addSteeringBehaviour(cohesion);
     myLegs.addSteeringBehaviour(alignment);
     yield return null;
 }
コード例 #14
0
ファイル: Boid.cs プロジェクト: ray10102/unity-boids
 // Update is called once per frame
 void Update()
 {
     velocity += Cohesion.getAffect(this, allBoids) * BoidConfig.Instance.cohesionStrength;
     velocity += Separation.getAffect(this, allBoids) * BoidConfig.Instance.separationStrength;
     velocity += Alignment.getAffect(this, allBoids) * BoidConfig.Instance.alignmentStrength;
     if (velocity.magnitude > BoidConfig.Instance.maxSpeed)
     {
         velocity = Vector3.Normalize(velocity) * BoidConfig.Instance.maxSpeed;
     }
     else if (velocity.magnitude < BoidConfig.Instance.minSpeed)
     {
         velocity = Vector3.Normalize(velocity) * BoidConfig.Instance.minSpeed;
     }
     transform.position += velocity * Time.deltaTime;
     transform.rotation  = Quaternion.LookRotation(velocity);
 }
コード例 #15
0
ファイル: Behaviors.cs プロジェクト: rc183/igf
 /// <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();
 }
コード例 #16
0
ファイル: Behaviors.cs プロジェクト: rc183/igf
 /// <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();
 }
コード例 #17
0
    private void CalculateMove(Boid boid)
    {
        Vector3 cohesionVector, separationVector, alignmentVector, seekVector, arriveVector;

        // calculate behaviours
        cohesionVector   = Cohesion.CalculateCohesion(boid) * cohesionWeight;
        separationVector = Separation.CalculateSeparation(boid) * separationWeight;
        alignmentVector  = Alignment.CalculateAlignment(boid) * alignmentWeight;
        seekVector       = Seek.CalculateSeek(boid, Target, maxSpeed) * seekWeight;
        arriveVector     = Arrive.CalculateArrive(boid, Target, arriveSlowingDistance, arriveMaxSpeed);

        // calculate vector
        var newVelocity = boid.Velocity + cohesionVector + separationVector + alignmentVector + seekVector + arriveVector;
        var newPosition = boid.Position + newVelocity;

        // limit
        newVelocity = LimitVelocity(newVelocity);

        boid.UpdateMove(newPosition, newVelocity);
    }
コード例 #18
0
ファイル: FlockWander.cs プロジェクト: minas1/flocking
    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);
    }
コード例 #19
0
 void Start()
 {
     cohesion = new Cohesion(flock.Flock);
 }
コード例 #20
0
    private void InitializeSecondaryCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        bool avoidingObstacle = false;

        this.Priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        this.Blended = new BlendedMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = 100f,
                avoidDistance   = 10f,
                lookAhead       = 10f
            };

            //Target = character.KinematicData
            //MovementDebugColor = Color.magenta
            if (!avoidingObstacle)
            {
                avoidingObstacle = avoidObstacleMovement._avoiding;
            }
            this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 8f));
            //this.Priority.Movements.Add(avoidObstacleMovement);
        }

        var straight = new DynamicStraightAhead
        {
            MaxAcceleration = MAX_ACCELERATION,
            Target          = character.KinematicData
        };


        var separation = new Separation
        {
            MaxAcceleration  = MAX_ACCELERATION,
            separationFactor = 3f,
            radius           = 5f,
            flock            = Characters
        };

        var flockVelocityMatch = new FlockVelocityMatching
        {
            flock             = Characters,
            radius            = 5.0f,
            fanAngle          = 60.0f,
            Target            = character.KinematicData,
            Character         = character.KinematicData,
            TimeToTargetSpeed = .1f
        };

        var cohesion = new Cohesion
        {
            flock      = Characters,
            radius     = 5.0f,
            fanAngle   = 60.0f,
            maxSpeed   = MAX_SPEED,
            slowRadius = 1f,
        };

        var fleeFromClick = new FleeFromClick
        {
            camera          = Camera.main,
            fleeRadius      = 10f,
            MaxAcceleration = MAX_ACCELERATION
        };

        this.Blended.Movements.Add(new MovementWithWeight(straight, 3f));
        this.Blended.Movements.Add(new MovementWithWeight(fleeFromClick, 4f));
        this.Blended.Movements.Add(new MovementWithWeight(separation, 1f));
        this.Blended.Movements.Add(new MovementWithWeight(flockVelocityMatch, 3f));
        this.Blended.Movements.Add(new MovementWithWeight(cohesion, 2f));
        character.Movement = this.Blended;
    }
コード例 #21
0
 void Start()
 {
     cohesion = new Cohesion(flock.Flock);
 }
コード例 #22
0
ファイル: Cohesion.cs プロジェクト: fylux/GameAI
 public override Steering GetSteering()
 {
     return(Cohesion.GetSteering(npc, threshold, decayCoefficient, maxAccel, visibleRays));
 }
コード例 #23
0
 public void CohesionOff()
 {
     behaviours.Remove(Cohesion.GetInstance());
 }
コード例 #24
0
ファイル: FlockGame.cs プロジェクト: minas1/flocking
    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);
    }
コード例 #25
0
ファイル: FlockGame.cs プロジェクト: minas1/flocking
    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);
    }
コード例 #26
0
ファイル: flock.cs プロジェクト: JeanPaulYazbek/IAgames
    // 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);
    }