I’m sorry if this isn’t a type of question I can ask here but I was wondering if someone would be able to help me understand a script that I rewrote in Unity which was originally written in Lua.
This Script:
public class Bla : MonoBehaviour {
public int spawnTimer = 0;
private GameObject[] bullets;
public float sineinc = 0;
private int speedchange = 20;
public GameObject projectile;
// Update is called once per frame
void Update () {
spawnTimer += 1;
sineinc = sineinc + 0.005f * Mathf.PI;
if(spawnTimer % 4 == 0)
{
var numBullets = 10;
for(int i = 1; i < numBullets+1; i++)
{
GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
int speed = 3;
float angle = (((2*Mathf.PI)/numBullets) * i) + (speedchange * Mathf.Cos(sineinc / 1.75f));
bullet.GetComponent<Rigidbody2D>().velocity = new Vector2(speed * Mathf.Cos(angle), speed * Mathf.Sin(angle));
//bullets.SetValue(bullet, i);
}
}
}
}
I understand what it does, it does this:

Creating multiple objects that spin around a point. The thing I don’t really understand is the Maths… well some of it at least.
One thing I don’t understand for example is this line of code: sineinc = sineinc + 0.005f * Mathf.PI;
Sineinc and speedchange seem to be used to cause a change in angle so it spins but I don’t understand why 0.005f is being times by Mathf.PI since it just seems to cause the spinning to get faster. (It’s simple things like that which i don’t understand XD)
I also don’t really understand how MathF.Cos and MathF.Sin is used in this situation. I have been learning a lot more about trigonometry but I still don’t see how it can really be used in these types of situations
Like I said, it’s mainly the maths I don’t understand that well so I was wondering if someone would possibly be able to explain it? I understand it’s quite a lot, sorry about that. I have been changing a lot of the values used to see what the changes do but It’s why it works that I want to know.
Thank you