Help translating this code to UnityScript

I got most of it down however there are a few lines that confuse me

    CharacterController controller = GetComponent<CharacterController>();
    float snapDistance = 1.1f; //Adjust this based on the CharacterController's height and the slopes you want to handle - my CharacterController's height is 1.8 
    RaycastHit hitInfo = new RaycastHit();
    if (Physics.Raycast(new Ray(transform.position, Vector3.down), out hitInfo, snapDistance)) {
        isGrounded = true;
        transform.position = hitInfo.point;
        transform.position = new Vector3(hitInfo.point.x, hitInfo.point.y + controller.height / 2, hitInfo.point.z);
    } else {
        isGrounded = false;
    }

Here's what I got so far



    var controller : CharacterController;
    var snapDistance : float = 1.1;
    var hitInfo : RaycastHit;//new RaycastHit() confuses me. What's the new for and why does he write RaycastHit for a second time and then follow it up with ()
    
    function Start()
    {
         controller = GetComponent(CharacterController);
    }
    
    function Update()
    {
       if(Physics.Raycast(what does new Ray do?(transform.position, Vector3.down), what does out do?, snapDistance))
       {
         isGrounded = true;
         transform.position = hitInfo.point;
         transform.position = /*not sure if new works in UnityScript*/ Vector3(hitInfo.point.x, hitInfo.point.y + controller.height / 2, hitInfo.point.z);
       }
       else
       {
         isGrounded = false;
       }
    }

Try this:

If you get any errors, post them.

var controller : CharacterController;
var snapDistance : float = 1.1;
var hitInfo : RaycastHit;

function Start()
{
  controller = GetComponent(CharacterController);
}

function Update()
{
  if(Physics.Raycast(transform.position, Vector3.down, hitInfo, snapDistance))
  {
    controller.isGrounded = true;
    transform.position = Vector3(hitInfo.point.x, hitInfo.point.y + controller.height / 2, hitInfo.point.z);
  }
  else
  {
    controller.isGrounded = false;
  }
}

I don’t use UnityScript, so take this with some precaution.

new is a keyword that constructs a new object that follows it, calling the constructor with the parameters. It should work the same in UnityScript

new Ray(transform.position, Vector3.down)

out is a keyword that tells the compiler that this value is changed by the function, and the proper value returned in that parameter. You should be able to just omit the out keyword, as far as I can tell.