I'm just learning Unity and I follow a tutorial for a simple game which I want to build up from.
I'm already mostly done with the course and at the end a "boss enemy" gets implemented.
Its special ability is, that it has some other GameObject (a fireball) floating around itself.
It is all done in a single line of code in the update method which I don't quite understand yet, so any explanation would be great.
Here is the code:
private void Update()
{
fireball.position = transform.position +
new Vector3(
-Mathf.Cos(Time.time * fireballSpeed) * distance,
Mathf.Sin(Time.time * fireballSpeed) * distance,
0);
}
fireball
is the transform of the object which floats aroundfireballSpeed
is a float which indicates the floating speeddistance
is the distance from the boss enemy
I get that we are just updating the transforms position but I don't quite understand the Time.time * fireballSpeed
part. I also get that Cos
and Sin
are returning positions for X and Y but I need to improve my math knowledge to completely wrap my head around it to be honest.
So any explanation would be great.