---
title: magneticField()
framework: spritekit
role: symbol
role_heading: Type Method
path: spritekit/skfieldnode/magneticfield()
---

# magneticField()

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

## Declaration

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

## Return Value

Return Value A new magnetic field node.

## Discussion

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 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 property and the physics body’s charge and 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 property of a magnetic field node is set by default to 2.

## See Also

### Creating Field Nodes

- [dragField()](spritekit/skfieldnode/dragfield().md)
- [electricField()](spritekit/skfieldnode/electricfield().md)
- [linearGravityField(withVector:)](spritekit/skfieldnode/lineargravityfield(withvector:).md)
- [noiseField(withSmoothness:animationSpeed:)](spritekit/skfieldnode/noisefield(withsmoothness:animationspeed:).md)
- [radialGravityField()](spritekit/skfieldnode/radialgravityfield().md)
- [springField()](spritekit/skfieldnode/springfield().md)
- [turbulenceField(withSmoothness:animationSpeed:)](spritekit/skfieldnode/turbulencefield(withsmoothness:animationspeed:).md)
- [velocityField(with:)](spritekit/skfieldnode/velocityfield(with:).md)
- [velocityField(withVector:)](spritekit/skfieldnode/velocityfield(withvector:).md)
- [vortexField()](spritekit/skfieldnode/vortexfield().md)
- [customField(evaluationBlock:)](spritekit/skfieldnode/customfield(evaluationblock:).md)
- [SKFieldForceEvaluator](spritekit/skfieldforceevaluator.md)
