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; }
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; }