title: unity 3.3, create local gravity on object
body: <p>Using Unity 3.3. visual studio express 2010. and c#.</p>
  
  <p>I need to make a script that will be attached to an object.
  This object will create its own gravity field that will attract- repel all objects in the environment.</p>
  
  <p>Unfortunately I'm not sure how to do this due to unitys physics. would I need the object to overide all other objects? do I overide unitys main physics ? hows this work?
  Or am I overcomplicating things when its a simple script?</p>
  
  <p>No I do not want to add a rigig body so the object falls with gravity, it must CREATE gravity that is a lot more powerfull.</p>
  
  <p>Cheers</p>
  
  <p>UPDATE!</p>
  
  <pre><code>public float radius = 5.0f;
  public float power = -20f;
  void Start () 
  {
      //GameObject gravityObject = GameObject.FindGameObjectWithTag("GravitySwell");
      //gravSlime = gravityObject.transform;      
  }
  
  void Update () 
  {
      Vector3 explosionPos = transform.position;
      Collider[] colliders = Physics.OverlapSphere(explosionPos, radius, 3);
      foreach (Collider hit in colliders)
      {
          if (!hit)
          {
              continue;
          }
          if (hit.rigidbody)
          {
              hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3);
          }
      }
  }
  }
  </code></pre>
  
  <p>this works as it adds a negative force that attracts the object.
  Problem is that when the attractive object this script is assigned to is in mid air. any objects caught fly towards it, but then seems to fall only to be attracted again.
  Any hints as to why ?</p>
  
  <p>I was thinking something like this, but nothing happens:</p>
  
  <pre><code>Vector3 direction = this.transform.position - hit.transform.position;
  direction.Normalize();
              //hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3);
              //hit.transform.position.;
  hit.rigidbody.isKinematic = false;
  hit.rigidbody.AddForce(direction);
  </code></pre>
  
  <p>UPDATE::
  Ok I was trying this out, its seems to work well but its attached to the object that is being attracted. Also I was hoping if someone had a better idea?</p>
  
  <pre><code>public void OnCollisionEnter(Collision col)
  {
  if(col.gameObject.tag == "GravitySwell")
  {
      Debug.Log("i hit it!!!");
      rigidbody.velocity = Vector3.zero;
  }
  }
  </code></pre>