private List <DynamicMovement> InitBoidMovements(List <DynamicCharacter> characters, IEnumerable <GameObject> obstacles)
    {
        List <DynamicMovement> avoidObstacleMovement = new List <DynamicMovement>();

        foreach (var obstacle in obstacles)
        {
            avoidObstacleMovement.Add(new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration    = MAX_ACCELERATION,
                AvoidMargin        = AVOID_MARGIN,
                MaxLookAhead       = MAX_LOOK_AHEAD,
                MovementDebugColor = Color.magenta
            });
        }

        var cohesion = new DynamicCohesion()
        {
            Flock              = this.Flock,
            MaxSpeed           = MAX_SPEED,
            MaxAcceleration    = MAX_ACCELERATION,
            StopRadius         = 0.0F,
            SlowRadius         = 6.0F,
            FlockRadius        = COHESION_RADIUS,
            FanAngle           = FAN_ANGLE,
            MovementDebugColor = Color.red
        };

        var separation = new DynamicSeparation()
        {
            Flock              = this.Flock,
            FlockRadius        = SEPARATION_RADIUS,
            MaxAcceleration    = MAX_ACCELERATION,
            SeparationFactor   = SEPARATION_FACTOR,
            MovementDebugColor = Color.blue
        };

        var matchVelocity = new DynamicFlockVelocityMatch()
        {
            Flock              = this.Flock,
            MaxAcceleration    = MAX_ACCELERATION,
            FlockRadius        = COHESION_RADIUS,
            FanAngle           = FAN_ANGLE,
            MovementDebugColor = Color.green
        };

        var followMouse = new DynamicFollowMouse()
        {
            MaxSpeed           = MAX_SPEED,
            MaxAcceleration    = MAX_ACCELERATION,
            StopRadius         = STOP_RADIUS,
            SlowRadius         = SLOW_RADIUS,
            Arrived            = new HashSet <KinematicData>(),
            MovementDebugColor = Color.gray
        };

        FollowMouseMovement = new MovementWithWeight(followMouse, 0);

        var blended = new BlendedMovement();

        blended.Movements.Add(new MovementWithWeight(cohesion, COHESION_WEIGHT));
        blended.Movements.Add(new MovementWithWeight(separation, SEPARATION_WEIGHT));
        blended.Movements.Add(new MovementWithWeight(matchVelocity, VELOCITY_MATCH_WEIGHT));
        blended.Movements.Add(FollowMouseMovement);

        var allMovements = new List <DynamicMovement>();

        allMovements.AddRange(avoidObstacleMovement);
        allMovements.Add(blended);

        return(allMovements);
    }
Beispiel #2
0
    private void InitializeCharacters(DynamicCharacter character, GameObject[] obstacles)
    {
        var Blended = new BlendedMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration    = MAX_ACCELERATION,
                AvoidMargin        = AVOID_MARGIN,
                MaxLookAhead       = MAX_LOOK_AHEAD,
                Character          = character.KinematicData,
                WhiskersLength     = MAX_WHISKERS_LOOK_AHEAD,
                WhiskersSpan       = MAX_WHISKERS_SPAN,
                MovementDebugColor = Color.magenta
            };
            Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 7));
        }

        var separation = new DynamicSeparation()
        {
            Character        = character.KinematicData,
            flock            = this.flock,
            maxAcceleration  = MAX_ACCELERATION,
            radius           = RADIUS,
            separationFactor = SEPARATION_FACTOR
        };

        var flockVelocityMatching = new DynamicFlockVelocityMatching()
        {
            Character       = character.KinematicData,
            flock           = this.flock,
            radius          = RADIUS,
            fanAngle        = FAN_ANGLE,
            MaxAcceleration = MAX_ACCELERATION
        };

        var cohesion = new DynamicCohesion()
        {
            Character       = character.KinematicData,
            flock           = this.flock,
            MaxAcceleration = MAX_ACCELERATION,
            radius          = RADIUS,
            fanAngle        = FAN_ANGLE
        };

        var straightAhead = new DynamicStraightAhead
        {
            MaxAcceleration    = MAX_ACCELERATION,
            Character          = character.KinematicData,
            MovementDebugColor = Color.yellow
        };

        Blended.Movements.Add(new MovementWithWeight(straightAhead, 3));
        Blended.Movements.Add(new MovementWithWeight(separation, 4));
        Blended.Movements.Add(new MovementWithWeight(flockVelocityMatching, 3));
        Blended.Movements.Add(new MovementWithWeight(cohesion, 3));

        character.Movement = Blended;
    }
Beispiel #3
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        target = new KinematicData();

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                MaxLookAhead    = MAX_LOOK_AHEAD,
                AvoidMargin     = AVOID_MARGIN,
                Character       = this.character.KinematicData,
                DebugColor      = Color.magenta
            };

            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 1000000000000000000000000000000000000.0f));
        }

        //foreach (var boid in characters)
        //{

        //TODO: add your AvoidObstacle movement here
        var separationMovement = new DynamicSeparation()
        {
            MaxAcceleration  = MAX_ACCELERATION,
            Character        = this.character.KinematicData,
            Radius           = RADIUS_SEPARATION,
            Flock            = characters,
            SeparationFactor = SEPARATION_FACTOR
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(separationMovement, 5.0f));

        var cohesionMovement = new DynamicCohesion()
        {
            MaxAcceleration = MAX_ACCELERATION,
            Character       = this.character.KinematicData,
            radius          = RADIUS_COHESION,
            flock           = characters,
            fanAngle        = FAN_ANGLE,
            Target          = target
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(cohesionMovement, 0.2f));

        var velocityMatchingMovement = new FlockVelocityMatching()
        {
            MaxAcceleration = MAX_ACCELERATION,
            Character       = this.character.KinematicData,
            Radius          = RADIUS_VELOCITY_MATCHING,
            Flock           = characters,
            FanAngle        = FAN_ANGLE,
            Target          = target
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(velocityMatchingMovement, 0.5f));
        //}


        this.character.Movement = this.blendedMovement;
    }
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        List <DynamicCharacter> otherCharacters = characters.Where(b => b != character).ToList();

        foreach (var obstacle in obstacles)
        {
            var avoid = new DynamicAvoidShort
            {
                Character         = this.character.KinematicData,
                avoidDistance     = 10.0f,
                lookAhead         = 13.0f,
                collisionDetector = obstacle.GetComponent <Collider>(),
                MaxAcceleration   = MAX_ACCELERATION,
                whiskerLength     = 6.5f
            };

            this.blendedMovement.Movements.Add(new MovementWithWeight(avoid, 22.0f));
        }

        var cohesion = new DynamicCohesion(otherCharacters)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            StopRadius      = 5f,
            SlowRadius      = 10f,
            MaxSpeed        = this.character.MaxSpeed,
            Radius          = 15f,
            FanAngle        = MathConstants.MATH_PI_4
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(cohesion, 6.0f));

        var velocity = new FlockVelocityMatching(otherCharacters)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            Radius          = 20f,
            FanAngle        = MathConstants.MATH_PI_4
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(velocity, 10.0f));

        var separation = new DynamicSeparation(otherCharacters)
        {
            Character        = this.character.KinematicData,
            MaxAcceleration  = MAX_ACCELERATION,
            Radius           = SEP_RADIUS,
            SeparationFactor = MAX_ACCELERATION * 1.5f
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(separation, 12.0f));

        var wander = new DynamicStraightAhead
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(wander, 1.0f));

        var seekMouse = new DynamicSeekMouse
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = this.character.MaxSpeed,
            StopRadius      = 1f,
            SlowRadius      = 10f
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(seekMouse, 4.0f));

        this.character.Movement = this.blendedMovement;
    }
Beispiel #5
0
        private BlendedMovement GenerateBlendingMovementFor(DynamicCharacter character)
        {
            var blending = new BlendedMovement
            {
                MaxAcceleration = this.MaximumAcceleration,
                Character = character.KinematicData
            };

            var cohesion = new DynamicCohesion(this)
            {
                Character = character.KinematicData,
                MaxAcceleration = this.MaximumAcceleration,
                MaxSpeed = this.MaximumSpeed,
                FlockRadius = this.FlockRadius,
                MovementDebugColor = Color.yellow
            };

            var separation = new DynamicSeparation(this)
            {
                Character = character.KinematicData,
                MaxAcceleration = this.MaximumAcceleration,
                FlockRadius = this.FlockRadius,
                SeparationFactor = this.SeparationFactor,
                MovementDebugColor = Color.red
            };

            var velocityMatch = new DynamicFlockVelocityMatching(this)
            {
                Character = character.KinematicData,
                MaxAcceleration = this.MaximumAcceleration,
                FlockRadius = this.FlockRadius,
                MovementDebugColor = Color.green
            };

            var collisionDetection = new PriorityMovement
            {
                Character = character.KinematicData,
                MovementDebugColor = Color.magenta
            };
            foreach (var obstacle in this.Obstacles)
            {
                var avoidMovement = new DynamicAvoidObstacle(obstacle)
                {
                    MaxAcceleration = this.MaximumAcceleration,
                    AvoidMargin = 4.0f,
                    MaxLookAhead = 10.0f,
                };

                collisionDetection.Movements.Add(avoidMovement);
            }

            var flockSeek = new DynamicFlockTarget(this)
            {
                Character = character.KinematicData,
                MaxAcceleration = this.MaximumAcceleration,
                MovementDebugColor = Color.cyan
            };

            blending.Movements.Add(new MovementWithWeight(cohesion));
            blending.Movements.Add(new MovementWithWeight(separation,2.0f));
            blending.Movements.Add(new MovementWithWeight(velocityMatch));
            blending.Movements.Add(new MovementWithWeight(collisionDetection,1000.0f));
            blending.Movements.Add(new MovementWithWeight(flockSeek));

            return blending;
        }