Exemple #1
0
    // Use this for initialization
    void Start()
    {
        Attractor = new Example_2_6_Attractor(CSizeX / 2, CSizeY / 2, 3, 0.4f);

        for (int i = 0; i < movers.Length; i++)
        {
            // TODO Fix NEW Warning when instatiating, make mono happy.
            movers[i]  = new Example_2_6_Mover();
            spheres[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            spheres[i].transform.position =
                new Vector3(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
        }
    }
    public Vector3 attract(Example_2_6_Mover m)
    {
        Vector3 force    = location - m.location;
        float   distance = force.magnitude;

        // TODO Constrain to some sueful Values; Look up how to
        //distance.constrain;
        distance = Mathf.Clamp(distance, 0.1f, 6f);

        force = force.normalized;
        float Strength = (G * mass * m.mass) / (distance * distance);

        force *= Strength;
        return(force);
    }