This document is about: FUSION 2
SWITCH TO

Magnets

Fusion XR prototyping addons

The Magnets addon provides a simple way to attract an object to others when it has been ungrabbed.

Magnets demo

Magnet types

Magnetic objects are described with the IMagnet interface. Several kinds of magnets exist.

  • MagnetPoint are network behavior, that will look for an IMagnet within their magnetRadius (with a Physics.OverlapSphere) to be attracted to them.
  • StaticMagnet can attract other objects, but won't move. They do not need to be placed under a NetworkedObject.

Magnet roles

Attractables

For those who can be attracted (MagnetPoint):

  • if attractedMagnetRotation is set to MatchAlignmentAxis, the attracted object will align its AlignmentAxisAsAttracted axis with the attractor AlignmentAxisAsAttracktor axis, but will leave the other axis untouched.
  • Otherwise, if set to MatchAlignmentAxisWithOrthogonalRotation, the attracted object will also rotate to only have 90 angles between other axis

Attractable objects contain a compatibleLayers layer mask field, and only attractors having their collider in such a compatible layer will attract them. Note that the additionalCompatibleLayer allows to add one layer using its name (for packaging convenience).

Attractor

For those who can be attracted (MagnetPoint, StaticMagnet), if attracktedMagnetMove is set to AttracktOnlyOnAlignmentAxis, instead of attracting objects to their transform's position, the magnet attracts them to the neareast point to the projection plane it defines with new Plane(planeDirection, transform.position), were planeDirection is determined by the alignmentAxisAsAttracktor value.

For convenience, it is possible to set the magnetLayer field to automatically find the layer having this name, and change the attractor layer to this one.

MagnetCoordinator

An object can contain several MagnetPoint. To make sure they they do not trigger all at once upon ungrab, but only the one the closest to a magnetic object, a MagneticCoordinator can be used. It prevents the MagnetPoint from looking themselves for a target, and will select the most appropriate magnet point based on its distance from a magnetic object.

Demo

A demo scene can be found in Assets\Photon\FusionAddons\Magnets\Demo\Scenes\ folder.

Dependencies

  • XRShared addon 2.0

Download

This addon latest version is included into the Industries addon project

It is also included into the free XR addon project

Supported topologies

  • shared mode

Changelog

  • Version 2.1.0:
    • Breaking changes: change classes and attributes names to clarify logic
    • Add proximity callbacks (unrelated to actual magnet snapping)
  • Version 2.0.2: Add onSnapToMagnet event
  • Version 2.0.1:
    • Fix to avoid magnet to try to attract to itself in some cases
    • Allows to set MagnetTarget axis for plane magnets
  • Version 2.0.0: First release
Back to top