Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Make sphere represent a range

Discussion in 'Scripting' started by Sajid, Mar 12, 2015.

  1. Sajid

    Sajid

    Joined:
    Mar 12, 2011
    Posts:
    199
    So I have a turret that has it's range defined by a float value: range

    I check the distance between the turret and it's target with Vector3.Distance, and it only targets it if the distance is lower than range then it does not shoot. I want to reprisent this by making a sphere that shows the range of the tower.

    This is what i did:
    Code (CSharp):
    1.         rangeIndicator.transform.localScale = new Vector3(range,range, range);
    Now, it scales fine, but the problem is that it seems to be way smaller than the actual range of the tower.

    I have a suspicion that transform.localScale uses some kind of other scale? because if, for example my range float = 20, the sphere scales to 20,20,20 but it's not the same size as the range of the tower.
     
  2. Pawscal

    Pawscal

    Joined:
    Mar 26, 2013
    Posts:
    11
    I would gess the diameter of the base sphere is one, so it's radius is 0.5, maybe you need to multiply your range by two.
     
  3. Sajid

    Sajid

    Joined:
    Mar 12, 2011
    Posts:
    199
    such a simple solution to an obvious problem. I'm really not on point today!

    Thanks.
     
  4. Pawscal

    Pawscal

    Joined:
    Mar 26, 2013
    Posts:
    11
    My pleasure :)