Search Unity

Make Random.InitState relative to a position ?

Discussion in 'Scripting' started by zenden_1, Feb 16, 2019.

  1. zenden_1

    zenden_1

    Joined:
    May 20, 2017
    Posts:
    53
    Hello, actually for the position i use vector.sqrmagnitude bot the problem with is if i have a gameObject in position ( 5,0,0 ) and another in position ( 0,5,0) they will have the same value.

    Code (CSharp):
    1.   void setSystemValue()
    2.     {
    3.         RaycastHit hit;
    4.         Ray ray = cam.ScreenPointToRay(Input.mousePosition);
    5.  
    6.  
    7.  
    8.         if (Physics.Raycast(ray, out hit, Mathf.Infinity))
    9.         {
    10.  
    11.  
    12.             Random.InitState((int)hit.transform.position.sqrMagnitude);
    13.  
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    So use the xyz values in a clever way to get a new number, maybe use each axis as a seed, take the 3 numbers and add/multiply/divide/subtract them at will to get a new seed.

    Theres probably a better way, but you get idea i hope.