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.

  • AttractableMagnet are network behavior, that will look for an IAttractorMagnet within their magnetRadius (with a Physics.OverlapSphere) to be attracted to them.
  • AttractorMagnet are MonoBehaviour that can attract other objects. They do not need to be placed under a NetworkedObject.

If an object can attract and be attracted, both components are required.

Magnet roles

AttractableMagnet

For magnets who can be attracted (AttractableMagnet):

  • if AttractedMagnetRotation is set to MatchAlignmentAxis, the attracted object will align its alignmentAxisAsAttracted axis with the attractor alignmentAxisAsAttractor axis, but will leave the other axes untouched.
  • Otherwise, if set to MatchAlignmentAxisWithOrthogonalRotation, the attracted object will also rotate to only have 90 degrees angles between other axes

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).

AttractorMagnet

On AttractorMagnet, if attractedMagnetMove is set to AttractOnlyOnAlignmentAxis, instead of attracting objects to their transform's position, the magnet attracts them to the nearest point to the projection plane it defines with new Plane(planeDirection, transform.position), were planeDirection is determined by the alignmentAxisAsAttractor 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.

Synchronization

This add-on only deals with moving the magnet locally, and then the NetworkTransform deals with the position synchronization for all clients. It does not store and sync the attachment status itself, so the snap event itself is "invisible" proxies and late joiners.

For this kind of callback/status needs, you can check the [MagnetAttachmentPoint class in the StructureCohesion add-on] (~~~/industries-samples/industries-addons/fusion-industries-addons-structure-cohesion#magnetattachmentpoint), which stores attachment information based on the magnet snap.

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.2.0:
    • Breaking changes:
      • split magnet in AttractorMagnet and AttractableMagnet
      • StaticMagnet should be replaced by AttractorMagnet
      • new attribute options to clarify logic even more
  • 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