Generating objects, angle problems

Hello,

Me and a group of classmates are currently working on creating a top down space-shooter game in which when the game starts, the system is created. We are running into the problem where it generates fine from an angle of 0 to 359, but when we try and restrict the angle(say 0 to 45) it does not accept that and spawns based on the 0 to 359 anyways.

One of the main chunks in in which this works is as follows.

if(Planets[spawn]==1)
				{
					int GenerateAngle = Random.Range(0,359);
					xpos = ((spawn+1)*50) * Mathf.Sin(GenerateAngle);
					zpos = ((spawn+1)*50) * Mathf.Cos(GenerateAngle);
					Vector3 PlanetPosition = new Vector3(xpos,0,zpos);
					Instantiate(SPlanet,PlanetPosition,transform.rotation);
					transform.GetComponent("Moon").SendMessage("MoonCreate",PlanetPosition);
					
				}

I’m not sure why it would be doing this, but any help would be great. Thank you!

dude the sin and cos functions work in RADIANS - can you believe it.

look here for more info

/Documentation/ScriptReference/Mathf.html

how old are you guys? get with your math teacher if you don’t understand radians.

I often just pop this in scripts …

function sine( D:float )
	{
	return Mathf.Sin( D * Mathf.Deg2Rad );
	}
function cosine( D:float )
	{
	return Mathf.Cos( D * Mathf.Deg2Rad );
	}

I think you have some other problems but that will get you started.

BTW regarding “== 1” you should get in to booleans.