Increase width and height of dounut seperatly?

I’m using the script segment near the bottom of this question in order to instantiate and position prefabs in a torus shaped area to make a asteroid belt. The problem I’ve run into is I can’t set the height of the tube or the width of the tube separately, it uses the shared radius. Anyhow, here is the code, see if you can find the solution where I couldn’t. Thanks :slight_smile:

Vector3 RandInTorus() {
		Vector3 dir = Vector3.up * ringMidlineRadius;
		dir = Quaternion.AngleAxis (Random.Range (0.0f, 360.0f), Vector3.forward) * dir;
		Vector3 axis = Vector3.Cross (dir, Vector3.forward);
		Vector3 dir2 = dir.normalized * Random.Range (0.0f, tubeRadius);
		dir2 = Quaternion.AngleAxis (Random.Range (0.0f, 360.0f), axis) * dir2;
		
		return transform.TransformPoint (dir + dir2);
	}

This might give you what you need - using the elliptical cross section (presuming I’ve figured the axes you are using right).

Get the angle you want for the offset from the centre line:

   var angle = Random.value * 360;

Then work out the proportion of the up and right amounts for an ellipse:

    var upAmount = cos(angle) * r1; //Where r1 is the radius at the maximum height point
    var fwdAmount = sin(angle) * r2; //Where r2 is the radius of the maximum width

    dir2 = Vector3.up * upAmount + dir * fwdAmount; 
    //This puts it on the radius - if you want it within then:
    dir2 *= Random.value;