Hello!
I am making a graph with a set amount of local (or relative?) maximum/minimum-points. Between these points there are lines containing 3 gameobjects. The maximum/minimum-points are randomly generated between y = 0f,1f. What i am trying to put the 3 gameobjects between the maximum/minimum-points, these 3 objects should follow the equation of a line that is calculated from said maximum/minimum-points.
I have done everything right, but what i cant figure out is how to reset the b value of the lines (y = ax+b).
This is the code with some comments:
using UnityEngine;
using System.Collections;
public class perlin : MonoBehaviour {
public GameObject point;
public GameObject[] points;
private float x;
private float y;
private float a;
private float b;
void Start () {
//Generetes a straight line of gameobjects
for (int i = 0; i < points.Length; i++){
x = i;
points _= Instantiate(point,new Vector3 (x*0.25f,y,0),transform.rotation) as GameObject;_
-
}*
-
//Sets the local maximum/minimum-points.*
-
for (int i = 0; i < points.Length; i+=4){*
_ Vector3 temp = points*.transform.position;_
_ temp.y = Random.Range(0f,1f);_
_ points.transform.position = temp;*_
* }*
* //Sets the position of the gameobjects between the local maximum/minimum-points.*
* for (int i = 0; i < points.Length; i++){*
* if ((i % 4) == 0 && i < points.Length - 4){*
_ if (points*.transform.position.y > points[i+4].transform.position.y){
a = -Mathf.Abs((points.transform.position.y-points[i+4].transform.position.y)/(points.transform.position.x-points[i+4].transform.position.x));
}
if (points.transform.position.y < points[i+4].transform.position.y){
a = Mathf.Abs((points.transform.position.y-points[i+4].transform.position.y)/(points.transform.position.x-points[i+4].transform.position.x));
}
b = points.transform.position.y; //HOW TO RESET THIS?
}*_
* if ((i % 4) != 0){*
_ Vector3 temp = points*.transform.position;
temp.y = apoints*.transform.position.x+b;
points.transform.position = temp;*_
* }*
* }*
* }*
}
Now, this first line of gameobjects is at its right position but the second, third, forth… is way out of position since b never resets to 0. If i reset b to 0 every 4th iteration of i (when the index is at a maximum/minimum-point) i think i could achive what i want, my question is how to do this in the code.
A poorly drawn picture of what i am trying to achive:
![alt text][1]
Any help is appretiated!
Thank you!
[1]: /storage/temp/60311-unityhelp.png