예제 #1
0
    private void InitializeMainCharacter(GameObject[] obstacles)
    {
        this.Priority = new PriorityMovement
        {
            Character = this.RedCharacter.KinematicData
        };

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

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidMargin = AVOID_MARGIN,
                MaxLookAhead = MAX_LOOK_AHEAD,
                WhiskerLookAhead = WHISKER_LOOK_AHEAD,
                Character = this.RedCharacter.KinematicData,
                whiskersLookAhead = WHISKER_LOOK_AHEAD,
                MovementDebugColor = Color.magenta
            };
            this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, obstacles.Length + this.Characters.Count));
            this.Priority.Movements.Add(avoidObstacleMovement);
        }

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

                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character = this.RedCharacter.KinematicData,
                    MaxAcceleration = MAX_ACCELERATION,

                    MaximumTimeLookAhead = MAX_TIME_AHEAD,
                    MovementDebugColor = Color.cyan

                };

                this.Priority.Movements.Add(avoidCharacter);
            }
        }

        /*
         * TODO: add your wander behaviour here!
         */
        var wander = new DynamicWander
        {
            Character = this.RedCharacter.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.yellow
        };

        this.Priority.Movements.Add(wander);

        this.Blended.Movements.Add(new MovementWithWeight(wander,5.0f));

        this.RedCharacter.Movement = this.Blended;

    }
예제 #2
0
    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;
    }
예제 #3
0
    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;
    }
예제 #4
0
    private void InitializeCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        BlendedMovement Blended;

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

        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle()
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidDistance = AVOID_MARGIN,
                LookAhead = MAX_LOOK_AHEAD,
                Character = character.KinematicData,
                Obstacle = obstacle,
                MovementDebugColor = Color.magenta
            };

              Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, (obstacles.Length + this.Flock.Count) * AVOIDOB));

        }

        var DynamicSeparationMovement = new DynamicSeparation()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.blue,
            Flock = this.Flock,
            SeparationFactor = FLOCK_SEPARATION_FACTOR,
            Radius = FLOCK_SEPARATION_RADIUS
        };

        Blended.Movements.Add(new MovementWithWeight(DynamicSeparationMovement, (obstacles.Length + this.Flock.Count) * SEPARATIONB));

        var DynamicCohesionMovement = new DynamicCohesion()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.blue,
            Flock = this.Flock,
            FanAngle = FLOCK_COHESION_FAN_ANGLE,
            radius = FLOCK_COHESION_RADIUS
        };

        Blended.Movements.Add(new MovementWithWeight(DynamicCohesionMovement, (obstacles.Length + this.Flock.Count) * COHESIONB));

        var DynamicFlockVelocityMatchMovement = new DynamicFlockVelocityMatch()
        {
            Character = character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.blue,
            Flock = this.Flock,
            FanAngle = FLOCK_VELOCITYMATCHING_FAN_ANGLE,
            radius = FLOCK_VELOCITYMATCHING_RADIUS
        };

        Blended.Movements.Add(new MovementWithWeight(DynamicFlockVelocityMatchMovement, (obstacles.Length + this.Flock.Count) * ALIGNB));

        character.Movement = Blended;
    }
예제 #5
0
    private void InitializeCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        var blended = new BlendedMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {
            DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle(obstacle, true)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidMargin = AVOID_MARGIN,
                MaxLookAhead = MAX_LOOK_AHEAD,
                Character = character.KinematicData,
                MovementDebugColor = Color.magenta
            };
            blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 15.0f));
        }

        DynamicCohesion cohesion = new DynamicCohesion(Characters)
        {
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed = MAX_SPEED,
            MovementDebugColor = Color.cyan,
            Character = character.KinematicData,
            Radius = 15f,
            FanAngle = MathConstants.MATH_PI_4
        };
        blended.Movements.Add(new MovementWithWeight(cohesion, 8.0f));

        DynamicSeparation separation = new DynamicSeparation(Characters)
        {
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.green,
            Character = character.KinematicData,
            Radius = 10f,
            SeparationFactor = MAX_ACCELERATION * 1.3f
        };
        blended.Movements.Add(new MovementWithWeight(separation, 10.0f));

        DynamicFlockVelocityMatch velocityMatching = new DynamicFlockVelocityMatch(Characters)
        {
            MaxAcceleration = MAX_ACCELERATION,
            MovementDebugColor = Color.black,
            Character = character.KinematicData,
            Radius = 20f,
            FanAngle = MathConstants.MATH_PI_4
        };
        blended.Movements.Add(new MovementWithWeight(velocityMatching, 8.0f));

        DynamicGoToPosition goToPosition = new DynamicGoToPosition()
        {
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed = MAX_SPEED,
            Character = character.KinematicData,
            MovementDebugColor = Color.blue,
            Radius = 10.0f
        };
        blended.Movements.Add(new MovementWithWeight(goToPosition, 8.0f));
        GoToPositionMovements.Add(goToPosition);

        if (soloMove)
        {
            if (useWander)
            {
                var wander = new DynamicWander
                {
                    MaxAcceleration = MAX_ACCELERATION,
                    MovementDebugColor = Color.yellow,
                    Character = character.KinematicData,
                    TurnAngle = MathConstants.MATH_PI_4 / 2,
                    WanderRadius = 2f,
                    WanderOffset = 3f
                };
                blended.Movements.Add(new MovementWithWeight(wander, 4.0f));
            }
            else
            {
                var straightAhead = new DynamicStraightAhead
                {
                    MaxAcceleration = MAX_ACCELERATION,
                    MovementDebugColor = Color.yellow,
                    Character = character.KinematicData
                };
                blended.Movements.Add(new MovementWithWeight(straightAhead, 4.0f));
            }
        }

        character.Movement = blended;
    }
예제 #6
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;
        }
예제 #7
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;
    }
    private void InitializeMainCharacter(GameObject[] obstacles)
    {
        this.Priority = new PriorityMovement
        {
            Character = this.RedCharacter.KinematicData
        };

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

        foreach (var obstacle in obstacles) {
            DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle (obstacle, true)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidMargin = AVOID_MARGIN,
                MaxLookAhead = MAX_LOOK_AHEAD,
                Character = this.RedCharacter.KinematicData,
                MaxWhiskersLookAhead = 5f,
                WhiskersAngle = MathConstants.MATH_PI_4 * 0.75f,
                MovementDebugColor = Color.magenta
            };
            this.Blended.Movements.Add (new MovementWithWeight (avoidObstacleMovement, 5.0f));
            this.Priority.Movements.Add (avoidObstacleMovement);
        }

        foreach (var otherCharacter in this.Characters) {
            if (otherCharacter != this.RedCharacter) {
                var avoidCharacter = new DynamicAvoidCharacter (otherCharacter.KinematicData)
                {
                    Character = this.RedCharacter.KinematicData,
                    MaxAcceleration = MAX_ACCELERATION,
                    AvoidMargin = AVOID_MARGIN,
                    MaxTimeLookAhead = MAX_TIME_LOOK_AHEAD,
                    MovementDebugColor = Color.cyan
                };

                this.Priority.Movements.Add (avoidCharacter);
            }
        }

        var wander = new DynamicWander
        {
            MaxAcceleration = MAX_ACCELERATION,
            Character = this.RedCharacter.KinematicData,
            MovementDebugColor = Color.yellow
        };

        this.Priority.Movements.Add (wander);
        this.Blended.Movements.Add (new MovementWithWeight (wander, obstacles.Length + this.Characters.Count));

        this.RedCharacter.Movement = this.Blended;
    }