コード例 #1
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidMargin     = AVOID_MARGIN,
                MaxLookAhead    = MAX_LOOK_AHEAD,
                WhiskerLength   = 6.0f,
                WhiskerAngle    = MathConstants.MATH_PI_4 / 3,
                Character       = this.character.KinematicData,
                DebugColor      = Color.magenta
            };
            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 3.0f));
            this.priorityMovement.Movements.Add(avoidObstacleMovement);
        }

        foreach (var otherCharacter in characters)
        {
            if (otherCharacter != this.character)
            {
                //TODO: add your AvoidCharacter movement here
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character        = this.character.KinematicData,
                    MaxAcceleration  = MAX_ACCELERATION,
                    MaxTimeLookAhead = 1f,
                    AvoidMargin      = AVOID_MARGIN,
                    DebugColor       = Color.cyan
                };

                this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 0.5f));
                this.priorityMovement.Movements.Add(avoidCharacter);
            }
        }

        var targetPosition = this.character.KinematicData.Position + (Vector3.zero - this.character.KinematicData.Position) * 2;

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, targetPosition)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            DebugColor      = Color.yellow
        };

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.Select(o => new StaticData(o.transform)).ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            NumSamples      = 15,
            IgnoreDistance  = 20.0f
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 1));
        this.character.Movement = this.priorityMovement;
    }
コード例 #2
0
    // When we create characters dinamically we need to update the ones that already exist
    public void UpdateAvoidCharacterList(List <MainCharacterController> characterControllers, GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        if (characterControllers.Any())
        {
            foreach (var otherCharacter in characterControllers)
            {
                if (otherCharacter.character != this.character)
                {
                    //TODO: add your AvoidCharacter movement here
                    var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.character.KinematicData)
                    {
                        Character       = this.character.KinematicData,
                        MaxAcceleration = MAX_ACCELERATION,
                        DebugColor      = Color.cyan
                    };

                    this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 2.0f));
                    this.priorityMovement.Movements.Add(avoidCharacter);
                }
            }
        }
        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            DebugColor      = Color.black
        };
    }
    private void InitializeMainCharacter(GameObject[] obstacles)
    {
        this.Priority = new PriorityMovement
        {
            Character = this.RedCharacter.KinematicData
        };

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

        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacleWhiskers(obstacle)
            {
                MaxAcceleration    = MAX_ACCELERATION,
                AvoidMargin        = AVOID_MARGIN,
                MaxLookAhead       = MAX_LOOK_AHEAD,
                Character          = this.RedCharacter.KinematicData,
                MovementDebugColor = Color.magenta
            };
            this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 5.0f));
            this.Priority.Movements.Add(avoidObstacleMovement);
        }

        foreach (var otherCharacter in this.Characters)
        {
            if (otherCharacter != this.RedCharacter)
            {
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character          = this.RedCharacter.KinematicData,
                    MaxAcceleration    = MAX_ACCELERATION,
                    CollisionRadius    = COLLISION_RADIUS,
                    MaxTimeLookAhead   = MAX_TIME_LOOK_AHEAD,
                    MovementDebugColor = Color.cyan
                };

                this.Priority.Movements.Add(avoidCharacter);
            }
        }

        var wander = new DynamicWander
        {
            WanderOrientation  = this.RedCharacter.KinematicData.orientation,
            Character          = this.RedCharacter.KinematicData,
            WanderOffset       = 20.0F,
            WanderRadius       = 10.0F,
            WanderRate         = WANDER_RATE,
            MaxAcceleration    = MAX_ACCELERATION,
            MovementDebugColor = Color.yellow
        };

        this.Priority.Movements.Add(wander);
        this.Blended.Movements.Add(new MovementWithWeight(wander, obstacles.Length + this.Characters.Count));

        this.RedCharacter.Movement = this.Blended;
    }
コード例 #4
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidDistance   = AVOID_MARGIN,
                LookAhead       = MAX_LOOK_AHEAD,
                Character       = this.character.KinematicData,
                Target          = new KinematicData(),
                DebugColor      = Color.magenta
            };

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

        foreach (var otherCharacter in characters)
        {
            if (otherCharacter != this.character)
            {
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character       = this.character.KinematicData,
                    MaxAcceleration = MAX_ACCELERATION,
                    CollisionRadius = AVOID_MARGIN,
                    DebugColor      = Color.cyan
                };

                this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 2.0f));
                this.priorityMovement.Movements.Add(avoidCharacter);
            }
        }

        var targetPosition = this.character.KinematicData.Position + (Vector3.zero - this.character.KinematicData.Position) * 2;

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, targetPosition)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            StopRadius      = 2.0f,
            SlowRadius      = 6.0f,
            DebugColor      = Color.yellow
        };

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.Select(o => new StaticData(o.transform)).ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 1));
        this.character.Movement = this.priorityMovement;
    }
コード例 #5
0
    public void InitializeMovement(List <Obstacle> obstacles, List <DynamicCharacter> characters)
    {
        //TODO: add your AvoidObstacle movement here
        var avoidObstacleMovement = new DynamicAvoidObstacles()
        {
            MaxAcceleration = MAX_ACCELERATION,
            AvoidMargin     = AVOID_MARGIN,
            MaxLookAhead    = MAX_LOOK_AHEAD,
            Character       = this.character.KinematicData,
            DebugColor      = Color.magenta,
            Target          = new KinematicData()
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 1f));
        this.priorityMovement.Movements.Add(avoidObstacleMovement);


        foreach (var otherCharacter in characters)
        {
            if (otherCharacter != this.character)
            {
                //TODO: add your AvoidCharacter movement here
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character        = this.character.KinematicData,
                    MaxAcceleration  = MAX_ACCELERATION,
                    CollisionRadius  = 0.2f,
                    MaxTimeLookAhead = MAX_TIME_LOOK_AHEAD,
                    DebugColor       = Color.cyan
                };

                this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 1.0f));
                this.priorityMovement.Movements.Add(avoidCharacter);
            }
        }

        var targetPosition = this.character.KinematicData.Position + (Vector3.zero - this.character.KinematicData.Position) * 2;

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, targetPosition)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            DebugColor      = Color.yellow
        };

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.Select(o => new StaticData(o.GameObject.transform)).ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            CharacterSize   = 3f,
            IgnoreDistance  = 20f
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 2f));
        this.character.Movement = this.rvoMovement;
    }
コード例 #6
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            //TODO: add your AvoidObstacle movement here
            var avoid = new DynamicAvoidShort
            {
                Character         = this.character.KinematicData,
                avoidDistance     = 5.0f,
                lookAhead         = 15.0f,
                collisionDetector = obstacle.GetComponent <Collider>(),
                MaxAcceleration   = MAX_ACCELERATION,
                whiskerLength     = 7.5f
            };

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

        foreach (var otherCharacter in characters)
        {
            if (otherCharacter != this.character)
            {
                //TODO: add your AvoidCharacter movement here
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character        = this.character.KinematicData,
                    maxAcceleration  = MAX_ACCELERATION,
                    collisionRadius  = 3f,
                    maxTimeLookAhead = 8f
                };

                this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 10.0f));
                this.priorityMovement.Movements.Add(avoidCharacter);
            }
        }

        /* TODO: add your wander behaviour here! */
        var wander = new DynamicWander
        {
            Character       = this.character.KinematicData,
            WanderOffset    = 5,
            WanderRate      = MathConstants.MATH_1_PI,
            MaxAcceleration = MAX_ACCELERATION
        };

        this.priorityMovement.Movements.Add(wander);

        this.blendedMovement.Movements.Add(new MovementWithWeight(wander, 1));
        this.character.Movement = this.blendedMovement;
    }
    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;
    }
コード例 #8
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidDistance   = AVOID_MARGIN,
                LookAhead       = MAX_LOOK_AHEAD,
                Character       = this.character.KinematicData,
                DebugColor      = Color.magenta
            };
            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 4.0f));
            this.priorityMovement.Movements.Add(avoidObstacleMovement);
        }

        foreach (var otherCharacter in characters)
        {
            if (otherCharacter != this.character)
            {
                var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                {
                    Character       = this.character.KinematicData,
                    MaxAcceleration = MAX_ACCELERATION,
                    AvoidMargin     = AVOID_MARGIN,
                    CollisionRadius = COLLISION_RADIUS,
                    DebugColor      = Color.cyan
                };

                this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 2.0f));
                this.priorityMovement.Movements.Add(avoidCharacter);
            }
        }

        var targetPosition = -this.character.KinematicData.Position;

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, targetPosition)
        {
            Character       = this.character.KinematicData,
            TimeToTarget    = TIME_TO_TARGET,
            SlowRadius      = SLOW_RADIUS,
            StopRadius      = STOP_RADIUS,
            MaxAcceleration = MAX_ACCELERATION,
            DebugColor      = Color.yellow
        };

        List <GameObject>    obs  = obstacles.ToList();
        List <KinematicData> obst = new List <KinematicData>();

        obst.AddRange(obs.Select(c => new KinematicData(new StaticData(c.transform))).ToList());

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obst, this.character.KinematicData)
        {
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            CharacterSize   = CHARACTER_SIZE,
            IgnoreDistance  = IGNORE_DISTANCE,
            NumberOfSamples = NUMBER_OF_SAMPLES,
            Weight          = RVO_WEIGHT
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 1f));
        this.character.Movement = this.priorityMovement;
    }
コード例 #9
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration = MAX_ACCELERATION,
                AvoidMargin     = AVOID_MARGIN,
                MaxLookAhead    = MAX_LOOK_AHEAD,
                Character       = this.character.KinematicData,
                DebugColor      = Color.magenta
            };
            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 2.0f));
            this.priorityMovement.Movements.Add(avoidObstacleMovement);
        }

        if (characters.Any())
        {
            foreach (var otherCharacter in characters)
            {
                if (otherCharacter != this.character)
                {
                    //TODO: add your AvoidCharacter movement here
                    //EX2
                    var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
                    {
                        Character       = this.character.KinematicData,
                        MaxAcceleration = MAX_ACCELERATION,
                        DebugColor      = Color.cyan,

                        MaxTimeLookAhead = MAX_TIME_LOOK_AHEAD,
                        AvoidMargin      = COLLISION_RADIUS,
                    };

                    this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 2.0f));
                    this.priorityMovement.Movements.Add(avoidCharacter);
                }
            }
        }

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, new Vector3(0.0f, 0.0f, 0.0f))
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            DebugColor      = Color.yellow
        };

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
            DebugColor      = Color.black
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 1));
        this.character.Movement = this.priorityMovement;
        this.ChangeTargetRandom();
    }
コード例 #10
0
    public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters)
    {
        foreach (var obstacle in obstacles)
        {
            var avoidObstacleMovement = new DynamicAvoidObstacle(obstacle)
            {
                MaxAcceleration  = MAX_ACCELERATION,
                AvoidMargin      = AVOID_MARGIN,
                MaxLookAhead     = MAX_LOOK_AHEAD,
                WhiskerLookAhead = WHISKER_LOOK_AHEAD,
                Character        = this.character.KinematicData,
                Target           = new KinematicData(),
                DebugColor       = Color.magenta
            };
            this.blendedMovement.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 15f));
            this.priorityMovement.Movements.Add(avoidObstacleMovement);
        }

        /*
         * foreach (var otherCharacter in characters)
         * {
         *  if (otherCharacter != this.character)
         *  {
         *      var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData)
         *      {
         *          Character = this.character.KinematicData,
         *          MaxAcceleration = 10f,
         *          CollisionRadius = AVOID_MARGIN,
         *          MaxTimeLookAhead = 3f,
         *          DebugColor = Color.cyan
         *      };
         *
         *      this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 3f));
         *      this.priorityMovement.Movements.Add(avoidCharacter);
         *  }
         * }
         */

        var avoidCharacter = new DynamicAvoidCharacter(characters.Where(c => c != this.character).Select(d => d.KinematicData).ToList())
        {
            Character        = this.character.KinematicData,
            MaxAcceleration  = 10f,
            CollisionRadius  = AVOID_MARGIN,
            MaxTimeLookAhead = 3f,
            DebugColor       = Color.cyan
        };

        this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 10f));
        this.priorityMovement.Movements.Add(avoidCharacter);

        var targetPosition = this.character.KinematicData.Position + (Vector3.zero - this.character.KinematicData.Position) * 2;

        this.patrolMovement = new DynamicPatrol(this.character.KinematicData.Position, targetPosition)
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            DebugColor      = Color.yellow
        };

        this.rvoMovement = new RVOMovement(this.patrolMovement, characters.Select(c => c.KinematicData).ToList(), obstacles.Select(o => new StaticData(o.transform)).ToList())
        {
            Character       = this.character.KinematicData,
            MaxAcceleration = MAX_ACCELERATION,
            MaxSpeed        = MAX_SPEED,
        };

        this.priorityMovement.Movements.Add(patrolMovement);
        this.blendedMovement.Movements.Add(new MovementWithWeight(patrolMovement, 1.5f));
        this.character.Movement = this.priorityMovement;
    }