raycast not doing good

Right now when i hit something with my raycast, it just tells me what it is... what i want the raycast to do is if it hits a rigidbody, make that rigidbody fly off as if it were hit by a bullet. thanks!

  function Update()
  {

    if(Input.GetMouseButton(0))

    {
      var forward = transform.TransformDirection(Vector3.forward);
      var hitInfo : RaycastHit;
      if (Physics.Raycast (transform.position, forward, hitInfo, 1000)) {
        print(hitInfo.collider);
      }
    }
  }

1 Answer

1

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html

Yea... Just get the rigid body, and do .AddForce ().

  function Update()
  {

    if(Input.GetMouseButton(0))

    {
      var forward = transform.TransformDirection(Vector3.forward);
      var hitInfo : RaycastHit;
      if (Physics.Raycast (transform.position, forward, hitInfo, 1000)) {
        hitInfo.rigidbody.AddForce(_________);
      }
    }
  }