Пример #1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (AllowControl && col.gameObject.GetComponent <ShapePieces>() != null)
     {
         ShapePieces piece     = col.gameObject.GetComponent <ShapePieces>();
         float       magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude;
         if (magnitude < attractDistance)
         {
             piece.GetAttracted(this, magnitude / attractDistance * attractForce);
         }
     }
 }
Пример #2
0
    void OnTriggerStay2D(Collider2D col)
    {
        if (Occupied)
        {
            return;
        }

        ShapePieces piece = col.GetComponentInParent <ShapePieces>();

        if (piece)
        {
            float magnitude = ((Vector2)col.transform.position - (Vector2)transform.position).magnitude;
            if (magnitude < snapDistance && Quaternion.Angle(transform.rotation, piece.transform.rotation) < 10f)
            {
                piece.SnugFit(this);
            }
            else if (magnitude < attractDistance)
            {
                piece.GetAttracted(this, ((attractDistance - magnitude) / attractDistance) * attractForce, magnitude / attractDistance);
            }
        }
    }