Search Unity

Distance as Float

Discussion in 'Scripting' started by marty, Dec 19, 2007.

  1. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Is there a Unity function that returns the distance between two points as a float, instead of as a Vector3 type?

    I know that I can calculate it with the help of my buddy Pythagorus, but I thought there might be a function for it.

    TIA!
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Vector3.Distance() ?

    Cheers,
    -Jon
     
  3. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Vector3.distance(a, b); // returns distance between a and b

    (a-b).magnitude;
     
  4. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    My bad.

    Vector3.Distance *does* return a float.

    :oops:
     
  5. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    You guys are fast!