cos / sin

what’s wrong with this for loop?
the print(rotOffset); returns the right numbers but the instantiated result is off?

for(var e=0; e<int.Parse(matching.AtomList[i+2].ToString()); e++)
		{	
			var	rotOffset:float=(360/(int.Parse(matching.AtomList[i+2].ToString())))*e;
			print (rotOffset);
			var r=1;//element.transform.localScale.x/2;
			var x=Mathf.Cos(rotOffset)*r;
			var y=Mathf.Sin(rotOffset)*r;
			var pos= element.transform.position+Vector3(x, y, 0);
			var rot=transform.rotation;
			rot=new Quaternion.Euler(0,0,rot.z+rotOffset);	
			var clone:GameObject = Instantiate(objToCopy, pos, rot);
			clone.transform.parent=element.transform;
		}

for example if int.Parse(matching.AtomList[i+2].ToString()) = 4, the print return 0, 90, 180, 270 which seems correct but the result looks like this:

I bet without even looking at your code that you’re measuring the angles in degrees, while Mathf.Sin and Mathf.Cos accept radians.

ah yes probably forgot about that, so i guess placing Mathf.Rad2Deg (x), Mathf.Rad2Deg(y) in the pos=Vecotr3 should fix it? or should it be Mathf.Sin(Mathf.Rad2Deg.(rotOffset));? I’ll try both…
ecit: just looked at the ref and i should just do * Mathf.Rad2Deg not Mathf.Rad2Deg(var); :slight_smile:

What you want is Mathf.Sin(rotOffset * Mathf.Deg2Rad), just like it says on the tin.

ok thanks a lot this fixed it
var x=(Mathf.Cos(rotOffset*Mathf.Deg2Rad))r;
var y=(Mathf.Sin(rotOffset
Mathf.Deg2Rad))*r;
just like you said :wink: