- Home /
I figured it out.
Generating randomness in a sphere. Only working horizontally. (Image in description)
Update, Fixed:
So basically I was adding randomly to the previous height, which was the vertex to the left. I needed to grab the vertex from above (one row above) compound it with the left vertex, grab the average and use that. Results as follows:
----------------------------------------------------------//
I used to have a random radius chosen for each point on the sphere. Which produced this result.
Then I started using a more complex generation system. Or at least the ideas of one. But because of my vertex loop I believe, my sphere terrain's horizontal is out of sync with it's vertical. As seen in this image.
My brain is currently fried, I'm sure it's a fairly simple issue but I didn't want to spend the next 8 hours fooling around. Figured someone would have done all that already. Any thoughts?
PS: I'll add my vertex generation code for inspection. If you've done sphere generation before it would help a lot towards understanding what's going on. My 'more complex terrain generator' is rather brutal and vulgar atm, any tips towards that would be appreciated as well.
for (i = 0; i < segments+1; i ++){
for (p = 0; p < (segments * 2)+ 1; p ++){
if(Random.Range(0,8) == 2){
savedRandom += Random.Range(-0.02,0.02);
}else{
savedRandom += Random.Range(-0.002, 0.002);
}
if(savedRandom > 0.02){
savedRandom = 0.02;
}else if(savedRandom < 0.0){
savedRandom = 0.0;
}
if ( i == 0 || i == segments || i == 1 || i == segments-1){
if( i == 1 || i == segments-1){
verts[ p + (i * ((segments * 2)+ 1 )) ] = new Vector3( posX2[p] * posX[i], posY[i], posY2[p] * posX[i] ) * radius * (1.0 - (savedRandom/2));
}else{
verts[ p + (i * ((segments * 2)+ 1 )) ] = new Vector3( posX2[p] * posX[i], posY[i], posY2[p] * posX[i] ) * radius * (1.0 - savedRandom);
}
if (p != 0){
verts[ p + (i * ((segments * 2)+ 1 )) ] = verts[ 0 + (i * ( (segments * 2) + 1 )) ];
}
}else if ( p == (segments * 2) ){
verts[ p + (i * ((segments * 2)+ 1 )) ] = verts[ 0 + (i * ( (segments * 2) + 1 )) ];
}else{
verts[ p + (i * ((segments * 2)+ 1 )) ] = new Vector3( posX2[p] * posX[i], posY[i], posY2[p] * posX[i] ) * radius * (1.0 - savedRandom);
}
}
Your else statement on line 6 is the same as the if statement above it ... this could be your problem.
There is an extra decimal place. :P There is no 'problem' with my current code. That code functions perfectly, it's just doesn't perform the right action. I need to change that code or get some new stuff in there.