Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Random.insideunitcircle is not starting at the origin 0,0;

Discussion in 'Scripting' started by calabi, Dec 9, 2018.

  1. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    40
    I'm having weird inconsistent behaviour with this function.

    I have two objects using the Random.insideUnitCircle and they are behaving in different ways. I can offset one using this and it behaves perfectly. It starts at the origin x = 0, z = 0 so I can move it using the code below to where I want it.

    Code example below.

    Code (CSharp):
    1.  
    2.             Tempprefabpos = Random.insideUnitCircle * 5 + TemporiginPos;
    3.  
    4.             PrefabPos.x =  Tempprefabpos.x;
    5.             PrefabPos.y = 0;
    6.             PrefabPos.z =  Tempprefabpos.y;
    7.  
    8.             Instantiate(BusinessPrefab, PrefabPos, Quaternion.identity);
    But on another object the origin is offset from 0,0 somehow, which means it moves off in weird tangents that I dont want when I try to offset it from the origin. I'm wondering how this could happen and what could effect it. It seems like the values are correct when I watch them in the debugger, but somehow during instantiation, or I don't know when its moving them to the wrong position.

    I'm wondering if anyone has any idea of what could be happening because I cant figure it out. I dont think its anything wrong with the code but I dont know. Is another object affecting it somehow?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    2,895
    Your best bet is to use Debug.Log() and a small subset of all the objects you want to spawn, and just track down where the math is going wrong.
     
  3. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    40
    Thanks, I think I've figured it out, it was going off the origin of the prefab object.
     
    Kurt-Dekker likes this.