예제 #1
0
        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);
        }
예제 #2
0
        private void OnTriggerExit(Collider other)
        {
            Magnet magnet = other.GetComponent <Magnet>();

            if (magnet != null)
            {
                attractedMagnets.Remove(magnet);
            }
        }
예제 #3
0
        private void OnTriggerEnter(Collider other)
        {
            Magnet magnet = other.GetComponent <Magnet>();

            if (magnet != null)
            {
                attractedMagnets.Add(magnet);
            }
        }