Example #1
0
    private void InitializeCharacter(DynamicCharacter character)
    {
        var blended = new BlendedMovement
        {
            Character          = character.KinematicData,
            MovementDebugColor = Color.black
        };


        var priority = new PriorityMovement
        {
            Character = character.KinematicData
        };

        // VELOCITY MATCHING
        var flockVelocityMatching = new FlockVelocityMatching()
        {
            Character          = character.KinematicData,
            Flock              = this.getCharactersKinematicData(this.Characters),
            MaxAcceleration    = MAX_ACCELERATION,
            MovementDebugColor = Color.green
        };

        // SEPARATION
        var flockSeparation = new FlockSeparation()
        {
            Character          = character.KinematicData,
            Flock              = this.getCharactersKinematicData(this.Characters),
            MaxAcceleration    = MAX_ACCELERATION,
            MovementDebugColor = Color.grey
        };

        // COHESION
        var flockCohesion = new FlockCohesion()
        {
            Character          = character.KinematicData,
            Flock              = this.getCharactersKinematicData(this.Characters),
            MaxAcceleration    = MAX_ACCELERATION,
            MovementDebugColor = Color.cyan
        };

        // OBSTACLE AVOIDANCE
        var obstacleAvoidMovement = new DynamicObstacleAvoid()
        {
            MaxAcceleration    = MAX_ACCELERATION / 2,
            Character          = character.KinematicData,
            MovementDebugColor = Color.magenta
        };

        // FLEE
        var flockFlee = new FlockFlee()
        {
            Character          = character.KinematicData,
            Flock              = this.getCharactersKinematicData(this.Characters),
            Target             = new KinematicData(),
            MaxAcceleration    = MAX_ACCELERATION * 3.0f,
            MovementDebugColor = Color.green
        };

        //TODO: ADD THE 3 MOVEMENTS
        blended.Movements.Add(new MovementWithWeight(flockSeparation, 1.5f));
        blended.Movements.Add(new MovementWithWeight(flockCohesion, 1.7f));
        blended.Movements.Add(new MovementWithWeight(flockVelocityMatching, 2.0f));
        blended.Movements.Add(new MovementWithWeight(flockFlee, 2.0f));

        priority.Movements.Add(obstacleAvoidMovement);
        priority.Movements.Add(blended);


        character.Movement = priority;
    }
Example #2
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;
    }
    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;
    }
Example #4
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        target = new KinematicData();

        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                MaxLookAhead    = MAX_LOOK_AHEAD,
                AvoidMargin     = AVOID_MARGIN,
                Character       = this.character.KinematicData,
                DebugColor      = Color.magenta
            };

            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 1000000000000000000000000000000000000.0f));
        }

        //foreach (var boid in characters)
        //{

        //TODO: add your AvoidObstacle movement here
        var separationMovement = new DynamicSeparation()
        {
            MaxAcceleration  = MAX_ACCELERATION,
            Character        = this.character.KinematicData,
            Radius           = RADIUS_SEPARATION,
            Flock            = characters,
            SeparationFactor = SEPARATION_FACTOR
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(separationMovement, 5.0f));

        var cohesionMovement = new DynamicCohesion()
        {
            MaxAcceleration = MAX_ACCELERATION,
            Character       = this.character.KinematicData,
            radius          = RADIUS_COHESION,
            flock           = characters,
            fanAngle        = FAN_ANGLE,
            Target          = target
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(cohesionMovement, 0.2f));

        var velocityMatchingMovement = new FlockVelocityMatching()
        {
            MaxAcceleration = MAX_ACCELERATION,
            Character       = this.character.KinematicData,
            Radius          = RADIUS_VELOCITY_MATCHING,
            Flock           = characters,
            FanAngle        = FAN_ANGLE,
            Target          = target
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(velocityMatchingMovement, 0.5f));
        //}


        this.character.Movement = this.blendedMovement;
    }