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;
    }
    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;
    }
Exemple #3
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;
    }
Exemple #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,
                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;
    }
    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();
    }
    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;
    }