---
title: "init(toAvoid:maxPredictionTime:)"
framework: gameplaykit
role: symbol
role_heading: Initializer
path: "gameplaykit/gkgoal/init(toavoid:maxpredictiontime:)-7oslq"
---

# init(toAvoid:maxPredictionTime:)

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

## Declaration

```swift
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

Return Value A new goal object.

## Discussion

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.

## See Also

### Creating Goals for Avoidance and Interception Behavior

- [init(toAvoid:maxPredictionTime:)](gameplaykit/gkgoal/init(toavoid:maxpredictiontime:)-96a0i.md)
- [init(toInterceptAgent:maxPredictionTime:)](gameplaykit/gkgoal/init(tointerceptagent:maxpredictiontime:).md)
