Hey guys. So, I’ve been messing around with math functions and just general math manipulation, and I’m kinda stumped on a concept that is probably really easy. Perhaps you guys can help me understand.
So, heres the full code. This is just moving an object on the Y axis by a sine wave.
public float amplitude;
public float frequency;
public Vector3 tempPos = new Vector3 ();
public Vector3 offset = new Vector3 ();
void Start()
{
offset = transform.position;
}
void Update()
{
tempPos = offset;
tempPos.y += Mathf.Sin (Time.fixedTime * Mathf.PI * frequency) * amplitude;
transform.position = tempPos;
}
specifically this part is what I’m confused on and can’t wrap my head around.
public Vector3 tempPos = new Vector3 ();
public Vector3 offset = new Vector3 ();
Can someone just explain to me why we are setting this as an empty Vector3 in relation to the rest of the code?
From experimenting, I can see what the difference is, but why? Perhaps its just the variable naming convention thats used… TempPos and offset. Is it appropriate to call it that in this situation in relation the what the codes doing? Sorry if this is a really newbie question lol. Funny I understand sine but not this.
So I guess, can someone just breakdown whats going on in this code? I wrote it half based on memory and half based on math logic (The actual sine wave logic)
Thanks!