Exemplo n.º 1
0
    //early initialization
    void Awake()
    {
        // Creating a new Dynamic Character
        this.character = new DynamicCharacter(this.gameObject);

        // Making sure we know all the possible destinations
        destinations = new List <Transform>();
        var goals = GameObject.Find("DestinationPoints").transform;

        for (int i = 0; i < goals.childCount; i++)
        {
            destinations.Add(goals.transform.GetChild(i));
        }

        // Initializing the Priority and Blended movements
        this.priorityMovement = new PriorityMovement
        {
            Character = this.character.KinematicData
        };

        this.blendedMovement = new BlendedMovement
        {
            Character = this.character.KinematicData
        };
    }
    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.º 3
0
    //early initialization
    void Awake()
    {
        this.character = new DynamicCharacter(this.gameObject);


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

        this.blendedMovement = new BlendedMovement
        {
            Character = this.character.KinematicData
        };
    }
Exemplo n.º 4
0
    //early initialization
    void Awake()
    {
        this.character        = new DynamicCharacter(this.gameObject);
        this.movementTextText = this.movementText.GetComponent <Text>();

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

        this.blendedMovement = new BlendedMovement
        {
            Character = this.character.KinematicData
        };
    }
    //early initialization
    void Awake()
    {
        this.character = new DynamicCharacter(this.gameObject)
        {
            MaxSpeed = MAX_SPEED,
            Drag     = DRAG
        };


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

        this.blendedMovement = new BlendedMovement
        {
            Character = this.character.KinematicData
        };
    }
Exemplo n.º 6
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;
    }
Exemplo n.º 7
0
        private BlendedMovement GenerateBlendingMovementFor(DynamicCharacter character)
        {
            var blending = new BlendedMovement
            {
                MaxAcceleration = this.MaximumAcceleration,
                Character       = character.KinematicData
            };

            var cohesion = new DynamicCohesion(this)
            {
                Character          = character.KinematicData,
                MaxAcceleration    = this.MaximumAcceleration,
                MaxSpeed           = this.MaximumSpeed,
                FlockRadius        = this.FlockRadius,
                MovementDebugColor = Color.yellow
            };

            var separation = new DynamicSeparation(this)
            {
                Character          = character.KinematicData,
                MaxAcceleration    = this.MaximumAcceleration,
                FlockRadius        = this.FlockRadius,
                SeparationFactor   = this.SeparationFactor,
                MovementDebugColor = Color.red
            };

            var velocityMatch = new DynamicFlockVelocityMatching(this)
            {
                Character          = character.KinematicData,
                MaxAcceleration    = this.MaximumAcceleration,
                FlockRadius        = this.FlockRadius,
                MovementDebugColor = Color.green
            };

            var collisionDetection = new PriorityMovement
            {
                Character          = character.KinematicData,
                MovementDebugColor = Color.magenta
            };

            foreach (var obstacle in this.Obstacles)
            {
                var avoidMovement = new DynamicAvoidObstacle(obstacle)
                {
                    MaxAcceleration = this.MaximumAcceleration,
                    AvoidMargin     = 4.0f,
                    MaxLookAhead    = 10.0f,
                };

                collisionDetection.Movements.Add(avoidMovement);
            }

            var flockSeek = new DynamicFlockTarget(this)
            {
                Character          = character.KinematicData,
                MaxAcceleration    = this.MaximumAcceleration,
                MovementDebugColor = Color.cyan
            };

            blending.Movements.Add(new MovementWithWeight(cohesion));
            blending.Movements.Add(new MovementWithWeight(separation, 2.0f));
            blending.Movements.Add(new MovementWithWeight(velocityMatch));
            blending.Movements.Add(new MovementWithWeight(collisionDetection, 1000.0f));
            blending.Movements.Add(new MovementWithWeight(flockSeek));

            return(blending);
        }