A simple way to do the mathf for lecture 60

Please let me know what you think, this is the whole oscillator script:

public class Oscillator : MonoBehaviour {

    [SerializeField] Vector3 movementVector;
    [SerializeField] float oscillationSpeed = 2f;

    Vector3 startingPos;

	// Use this for initialization
	void Start () {
        startingPos = transform.position;
	}
	
	// Update is called once per frame
	void Update () {
        float movementFactor = (Mathf.Sin(Time.time * oscillationSpeed))/2f + 0.5f;

        Vector3 offset = movementVector * movementFactor;

        transform.position = startingPos + offset;
	}
}
2 Likes

This works perfectly! Why did Ben let us do such complicated things D:

Thank you! I can understand this streamlined solution pretty easily compared to the more complicated one in the video. I can see why he wanted to get into the concept of tau, but for me it was one too many abstract concepts for a single video. Perhaps he assumes most of us have high school level trig down cold, haha… for me that was a long time ago. :wink:

Awesome! Glad it helped.

Nice, This code helped me understand more by looking at the other perspective.

Privacy & Terms