Пример #1
0
    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;
    }
Пример #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 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;
    }
Пример #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 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;
    }