Exemple #1
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;
    }
Exemple #2
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;
    }
    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;
    }