<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKGoal/init(toAvoid:maxPredictionTime:)-7oslq",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKGoal(cm)goalToAvoidObstacles:maxPredictionTime:"
  },
  "title" : "init(toAvoid:maxPredictionTime:)"
}
-->

# init(toAvoid:maxPredictionTime:)

Creates a goal whose effect is to make an agent avoid colliding with the specified static obstacles.

```
convenience init(toAvoid obstacles: [GKObstacle], maxPredictionTime: TimeInterval)
```

## Parameters

`obstacles`

The static obstacles with which to avoid collisions.

`maxPredictionTime`

The amount of time during which to predict collisions.

## Return Value

A new goal object.

## Discussion

The `maxPredictionTime` parameter controls how far in the future a predicted collision must be in order for the agent to take action to avoid it. For example, if this parameter has a low value, an agents speeding toward an obstacle will not swerve or slow until a collision is imminent (and depending on the properties of that agent, it might not be able to move quickly enough to avoid colliding). If this parameter has a high value, the agent will change course leisurely, well before colliding.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)