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

# magnetic()

Creates a field that attracts or repels objects based on their electrical charge, velocity, and distance from the field’s axis.

```
class func magnetic() -> SCNPhysicsField
```

## Return Value

A physics field object. To use the field in a scene, attach it to the [`physicsField`](/documentation/SceneKit/SCNNode/physicsField) property of an [`SCNNode`](/documentation/SceneKit/SCNNode) object.

## Discussion

Use this field type to make objects behave differently from one another when they enter a region, or to make an object’s behavior different from its mass based behavior. A magnetic field behaves according to the second part of the Lorentz force equation modeling real-world electromagnetic forces—the field applies a force determined by the cross product of an object’s velocity vector and the magnetic field vector at the object’s location, with magnitude proportional to the object’s electric charge.

By default, physics bodies and particle systems have no electric charge, so they are unaffected by electric and magnetic fields. Use the [`charge`](/documentation/SceneKit/SCNPhysicsBody/charge) property of a physics body or the [`particleCharge`](/documentation/SceneKit/SCNParticleSystem/particleCharge) property of a particle system to add charge-based behavior.

When the field’s [`strength`](/documentation/SceneKit/SCNPhysicsField/strength) value is positive (the default), the magnetic field vectors circulate counterclockwise relative to the field’s [`direction`](/documentation/SceneKit/SCNPhysicsField/direction) vector. (That is, the magnetic field models a real-world magnetic field created by current in a wire oriented in the field’s direction.) To make field vectors circulate clockwise, set the field’s [`strength`](/documentation/SceneKit/SCNPhysicsField/strength) property to a negative value.

> Note:
> This ``doc://com.apple.scenekit/documentation/SceneKit/SCNPhysicsField`` option models the real-world physics effect of magnetic fields on moving, electrically charged bodies, not the behavior of permanent magnets or electromagnets. To make objects in your scene simply attract or repel one another, use a different field type. For example, a field created by the ``doc://com.apple.scenekit/documentation/SceneKit/SCNPhysicsField/radialGravity()`` method attracts or repels all dynamic bodies near it according to its ``doc://com.apple.scenekit/documentation/SceneKit/SCNPhysicsField/strength`` property, and a field created by the ``doc://com.apple.scenekit/documentation/SceneKit/SCNPhysicsField/electric()`` method selectively attracts or repels bodies according to their electric charge.

The default [`falloffExponent`](/documentation/SceneKit/SCNPhysicsField/falloffExponent) value for a magnetic field is `2.0`, indicating that the field’s effect diminishes with the square of distance from its center.

---

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)