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

        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacleWhiskers(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)
            {
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character          = character.KinematicData,
                    MaxAcceleration    = MAX_ACCELERATION,
                    CollisionRadius    = COLLISION_RADIUS,
                    MaxTimeLookAhead   = MAX_TIME_LOOK_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;
    }
Exemplo n.º 2
0
    private void InitializeCharacters(DynamicCharacter character, GameObject[] obstacles)
    {
        var Blended = new BlendedMovement
        {
            Character = character.KinematicData
        };

        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration    = MAX_ACCELERATION,
                AvoidMargin        = AVOID_MARGIN,
                MaxLookAhead       = MAX_LOOK_AHEAD,
                Character          = character.KinematicData,
                WhiskersLength     = MAX_WHISKERS_LOOK_AHEAD,
                WhiskersSpan       = MAX_WHISKERS_SPAN,
                MovementDebugColor = Color.magenta
            };
            Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 7));
        }

        var separation = new DynamicSeparation()
        {
            Character        = character.KinematicData,
            flock            = this.flock,
            maxAcceleration  = MAX_ACCELERATION,
            radius           = RADIUS,
            separationFactor = SEPARATION_FACTOR
        };

        var flockVelocityMatching = new DynamicFlockVelocityMatching()
        {
            Character       = character.KinematicData,
            flock           = this.flock,
            radius          = RADIUS,
            fanAngle        = FAN_ANGLE,
            MaxAcceleration = MAX_ACCELERATION
        };

        var cohesion = new DynamicCohesion()
        {
            Character       = character.KinematicData,
            flock           = this.flock,
            MaxAcceleration = MAX_ACCELERATION,
            radius          = RADIUS,
            fanAngle        = FAN_ANGLE
        };

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

        Blended.Movements.Add(new MovementWithWeight(straightAhead, 3));
        Blended.Movements.Add(new MovementWithWeight(separation, 4));
        Blended.Movements.Add(new MovementWithWeight(flockVelocityMatching, 3));
        Blended.Movements.Add(new MovementWithWeight(cohesion, 3));

        character.Movement = Blended;
    }
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        List <DynamicCharacter> otherCharacters = characters.Where(b => b != character).ToList();

        foreach (var obstacle in obstacles)
        {
            var avoid = new DynamicAvoidShort
            {
                Character         = this.character.KinematicData,
                avoidDistance     = 10.0f,
                lookAhead         = 13.0f,
                collisionDetector = obstacle.GetComponent <Collider>(),
                MaxAcceleration   = MAX_ACCELERATION,
                whiskerLength     = 6.5f
            };

            this.blendedMovement.Movements.Add(new MovementWithWeight(avoid, 22.0f));
        }

        var cohesion = new DynamicCohesion(otherCharacters)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            StopRadius      = 5f,
            SlowRadius      = 10f,
            MaxSpeed        = this.character.MaxSpeed,
            Radius          = 15f,
            FanAngle        = MathConstants.MATH_PI_4
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(cohesion, 6.0f));

        var velocity = new FlockVelocityMatching(otherCharacters)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            Radius          = 20f,
            FanAngle        = MathConstants.MATH_PI_4
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(velocity, 10.0f));

        var separation = new DynamicSeparation(otherCharacters)
        {
            Character        = this.character.KinematicData,
            MaxAcceleration  = MAX_ACCELERATION,
            Radius           = SEP_RADIUS,
            SeparationFactor = MAX_ACCELERATION * 1.5f
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(separation, 12.0f));

        var wander = new DynamicStraightAhead
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(wander, 1.0f));

        var seekMouse = new DynamicSeekMouse
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = this.character.MaxSpeed,
            StopRadius      = 1f,
            SlowRadius      = 10f
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(seekMouse, 4.0f));

        this.character.Movement = this.blendedMovement;
    }
Exemplo n.º 4
0
    private void InitializeSecondaryCharacter(DynamicCharacter character, GameObject[] obstacles)
    {
        bool avoidingObstacle = false;

        this.Priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

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

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = 100f,
                avoidDistance   = 10f,
                lookAhead       = 10f
            };

            //Target = character.KinematicData
            //MovementDebugColor = Color.magenta
            if (!avoidingObstacle)
            {
                avoidingObstacle = avoidObstacleMovement._avoiding;
            }
            this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 8f));
            //this.Priority.Movements.Add(avoidObstacleMovement);
        }

        var straight = new DynamicStraightAhead
        {
            MaxAcceleration = MAX_ACCELERATION,
            Target          = character.KinematicData
        };


        var separation = new Separation
        {
            MaxAcceleration  = MAX_ACCELERATION,
            separationFactor = 3f,
            radius           = 5f,
            flock            = Characters
        };

        var flockVelocityMatch = new FlockVelocityMatching
        {
            flock             = Characters,
            radius            = 5.0f,
            fanAngle          = 60.0f,
            Target            = character.KinematicData,
            Character         = character.KinematicData,
            TimeToTargetSpeed = .1f
        };

        var cohesion = new Cohesion
        {
            flock      = Characters,
            radius     = 5.0f,
            fanAngle   = 60.0f,
            maxSpeed   = MAX_SPEED,
            slowRadius = 1f,
        };

        var fleeFromClick = new FleeFromClick
        {
            camera          = Camera.main,
            fleeRadius      = 10f,
            MaxAcceleration = MAX_ACCELERATION
        };

        this.Blended.Movements.Add(new MovementWithWeight(straight, 3f));
        this.Blended.Movements.Add(new MovementWithWeight(fleeFromClick, 4f));
        this.Blended.Movements.Add(new MovementWithWeight(separation, 1f));
        this.Blended.Movements.Add(new MovementWithWeight(flockVelocityMatch, 3f));
        this.Blended.Movements.Add(new MovementWithWeight(cohesion, 2f));
        character.Movement = this.Blended;
    }