Animation curve

I wanted to have a linear baseline for my factor. So instead of a sine wave, I made an oscillator that increases its value multiplied by a direction variable which then changes whenever the factor gets to 1 or 0. This would result in a curve more like this: image

Then I added an animation curve property on top of that which can be set from the inspector along with a minimum offset and a maximum offset which ultimately becomes minOffset + (maxOffset-minOffset) * curve.Evaluate(factor) to calculate the Vector3 offset relative to the factor’s current value.
oscillate

Turned it all into an abstract class called BaseOscillator which inherits from MonoBehaviour. Implements the oscillating features in the Update method and then calls an abstract Oscillate(Vector3 offset) method with the current offset, which is left to the implementing class to implement. This way the same code can be used for manipulating position or scaling or whatever you want that uses a Vector3 basically.

Privacy & Terms