<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/SKFieldNode/magneticField()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKFieldNode(cm)magneticField"
  },
  "title" : "magneticField()"
}
-->

# magneticField()

Creates a field node that applies a magnetic force based on the velocity and electrical charge of the physics bodies.

```
class func magneticField() -> SKFieldNode
```

## Return Value

A new magnetic field node.

## Discussion

The force generated by this field is directed on a line that is determined by calculating the cross-product between the direction of the the physics body’s [`velocity`](/documentation/SpriteKit/SKPhysicsBody/velocity) property and a line traced between the field node and the physics body. This field models the second part of the Lorentz equation:

*F = qvB*

Where *F* equals force, *q* equals charge, *v* equals velocity, *B* equals magnetic field and *E* equals electric field.

The force has a magnitude proportional to the field’s [`strength`](/documentation/SpriteKit/SKFieldNode/strength) property and the physics body’s [`charge`](/documentation/SpriteKit/SKPhysicsBody/charge) and [`velocity`](/documentation/SpriteKit/SKPhysicsBody/velocity) properties. Therefore, physics bodies that are either stationary or with a charge of zero will not be affected by a magnetic field. Magnetic fields with a negative strength value impart a clockwise spin on the physics bodies they affect, while a positive strength give a clockwise spin.The [`falloff`](/documentation/SpriteKit/SKFieldNode/falloff) property of a magnetic field node is set by default to `2`.

---

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)