Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. 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:
    43
    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:
    3,125
    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:
    43
    Thanks, I think I've figured it out, it was going off the origin of the prefab object.
     
    Kurt-Dekker likes this.