---
title: "distance(_:to:in:)"
framework: spritekit
role: symbol
role_heading: Type Method
path: "spritekit/skconstraint/distance(_:to:in:)"
---

# distance(_:to:in:)

Creates a constraint that keeps a node within a certain distance of a point in another node’s coordinate system.

## Declaration

```swift
class func distance(_ range: SKRange, to point: CGPoint, in node: SKNode) -> Self
```

## Parameters

- `range`: The range of allowed distances.
- `point`: The point to use as the target point.
- `node`: The node whose coordinate system the point is specified in.

## Return Value

Return Value A new constraint.

## Discussion

Discussion Each time when constraints are applied, a line is projected between the node’s position and the target point. The distance between the two points is calculated, and if it lies outside the specified range, the node is pushed or pulled along this line until it lies within the range.

## See Also

### Creating Distance Constraints

- [distance(_:to:)](spritekit/skconstraint/distance(_:to:)-6507j.md)
- [distance(_:to:)](spritekit/skconstraint/distance(_:to:)-7yk7n.md)
