private void InitializeSecondaryCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        var priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {

            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                avoidDistance = AVOID_MARGIN,
                lookAhead = MAX_LOOK_AHEAD,
                Character = this.RedCharacter.KinematicData,
                whiskersLookAhead = WHISKER_LOOK_AHEAD,
                MovementDebugColor = Color.magenta
            };
            priority.Movements.Add(avoidObstacleMovement);


        }

        foreach (var otherCharacter in this.Characters)
        {
            if (otherCharacter != character)
            {

                //TODO: add your avoidCharacter movement here
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character = character.KinematicData,
                    MaxAcceleration = MAX_ACCELERATION,
                    AvoidMargin = AVOID_MARGIN,
                    MaximumTimeLookAhead = MAX_TIME_AHEAD,
                    MovementDebugColor = Color.cyan

                };

                priority.Movements.Add(avoidCharacter);
            }
        }

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

        priority.Movements.Add(straightAhead);

        character.Movement = priority;
    }
    private void InitializeSecondaryCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        var priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {

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

            //priority.Movements.Add(avoidObstacleMovement);
        }

        foreach (var otherCharacter in this.Characters)
        {
            if (otherCharacter != character)
            {
                //TODO: add your avoidCharacter movement here
                //var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                //{
                //    Character = character.KinematicData,
                //    MaxAcceleration = MAX_ACCELERATION,
                //    AvoidMargin = AVOID_MARGIN,
                //    MovementDebugColor = Color.cyan
                //};

                //priority.Movements.Add(avoidCharacter);
            }
        }

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

        priority.Movements.Add(straightAhead);

        character.Movement = priority;
    }
Example #3
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;
        }
    private void InitializeSecondaryCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        var priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                avoidDistance = AVOID_MARGIN,
                lookAhead = MAX_LOOK_AHEAD,
                Character = this.RedCharacter.KinematicData,
                whiskersLookAhead = WHISKER_LOOK_AHEAD,
                MovementDebugColor = Color.magenta
            };
            var AvoidObjects = new BlendedMovement();
            AvoidObjects.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 1.0f));
            priority.Movements.Add(AvoidObjects);
        }

        var FlockMovement = new BlendedMovement();

        var boidseparation = new DynamicSeparation(Characters)
        {
            Character = this.RedCharacter.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            SeparationFactor = SEPARATION_FACTOR,
            Radius = RADIUS,
            MovementDebugColor = Color.green
        };
        FlockMovement.Movements.Add(new MovementWithWeight(boidseparation, 5.0f));

        var boidcohesion = new DynamicCohesion(Characters)
        {
            Character = this.RedCharacter.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            FanAngle = FAN_ANGLE,
            Radius = RADIUS,
            MovementDebugColor = Color.red
        };
        FlockMovement.Movements.Add(new MovementWithWeight(boidcohesion, 10.0f));

        var boidvelocity = new DynamicFlockVelocityMatching(Characters)
        {
            Character = this.RedCharacter.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            FanAngle = FAN_ANGLE,
            Radius = RADIUS,
            MovementDebugColor = Color.black
        };
        FlockMovement.Movements.Add(new MovementWithWeight(boidvelocity, 3.0f));

        var mouse = new DynamicMouseSeek
        {
            Character = this.RedCharacter.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.blue,
        };
        FlockMovement.Movements.Add(new MovementWithWeight(mouse, 8.0f));
        priority.Movements.Add(FlockMovement);

        character.Movement = priority;
    }
Example #5
0
    private void InitializeSecondaryCharacter(DynamicCharacter character, bool isPriority)
    {
        var priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        var blended = new BlendedMovement
        {
            Character = character.KinematicData,
        };

        var avoidObstacleMovement = new DynamicAvoidObstacle()
        {
            MaxAcceleration = MAX_ACCELERATION,
            AvoidMargin = AVOID_MARGIN,
            MaxLookAhead = MAX_LOOK_AHEAD,
            Character = character.KinematicData,
            MovementDebugColor = Color.magenta,
            Obstacles = obstacles
        };
        blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, OBSTACLE_AVOIDANCE_WEIGHT));
        priority.Movements.Add(avoidObstacleMovement);

        var clickArrive = new DynamicClickArrive()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovingTarget = new KinematicData(),
            SlowRadius = 5f,
            StopRadius = 3.5f,
            TimeToTargetSpeed = 1.0f,
            Target = new KinematicData(),
        };
        blended.Movements.Add(new MovementWithWeight(clickArrive, CLICK_ARRIVE_WEIGHT));
        priority.Movements.Add(clickArrive);

        var cohesionCharacter = new DynamicCohesion()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.yellow,
            MovingTarget = new KinematicData(),
            SlowRadius = 5f,
            StopRadius = 3.5f,
            TimeToTargetSpeed = 1.0f,
            Target = new KinematicData(),
            FanAngle = FAN_ANGLE,
            Radius = COHESION_RADIUS,
            Flock = CharactersKinData
        };
        blended.Movements.Add(new MovementWithWeight(cohesionCharacter, COHESION_WEIGHT));
        priority.Movements.Add(cohesionCharacter);

        var separationCharacter = new DynamicSeparation()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.blue,
            Target = new KinematicData(),
            Flock = CharactersKinData,
            Radius = SEPARATION_RADIUS,
            SeparationFactor = SEPARATION_FACTOR
        };
        blended.Movements.Add(new MovementWithWeight(separationCharacter, SEPARATION_WEIGHT));
        priority.Movements.Add(separationCharacter);

        var flockVelocityMatch = new DynamicFlockVelocityMatching()
        {
            Character = character.KinematicData,
            FanAngle = FAN_ANGLE,
            Flock = CharactersKinData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.black,
            MovingTarget = new KinematicData(),
            Radius = COHESION_RADIUS,
            Target = new KinematicData(),
            TimeToTargetSpeed = 1.5f
        };
        blended.Movements.Add(new MovementWithWeight(flockVelocityMatch, MATCH_SPEED_WEIGHT));
        priority.Movements.Add(flockVelocityMatch);
        if (isPriority)
            character.Movement = priority;
        else character.Movement = blended;
    }