コード例 #1
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;
    }
コード例 #2
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;
    }
コード例 #3
0
ファイル: PriorityManager.cs プロジェクト: lenyy/IAJ
    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;
    }
コード例 #4
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();
    }
コード例 #5
0
ファイル: Flock.cs プロジェクト: IAJ-g04/Lab8
        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);
        }
コード例 #6
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;
    }
コード例 #7
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;
    }
コード例 #8
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;
    }