private Vector3 CalculateForce(Magnet magnet, Vector3 currentPosition) { Vector3 direction = magnet.transform.position - currentPosition; float index = (magnet.radius - direction.magnitude) / magnet.radius; return(direction * magnet.strength * index); }
private void OnTriggerExit(Collider other) { Magnet magnet = other.GetComponent <Magnet>(); if (magnet != null) { attractedMagnets.Remove(magnet); } }
private void OnTriggerEnter(Collider other) { Magnet magnet = other.GetComponent <Magnet>(); if (magnet != null) { attractedMagnets.Add(magnet); } }