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