oscillate
Modular script for making objects bob up and down, or similar effects. Note: 8.1 users will have to fix the usage of 'var'
Script oscillate
/* Calculates an oscillating value with the given parameters.
oscillate(magnitude, period)
magnitude - distance the value deviates from 0
period - number of steps it takes to do a full positive and negative cycle
Note: depends on the global variable "count" being incremented by 1 every step
*/
var magnitude = argument0
var period = argument1
return magnitude * sin((global.count mod period)/period*pi*2)
Create of some controller object (e.g. "world")
global.count = 0
Step of some controller object (e.g. "world")
global.count += 1
Example use: in some object's step event
// make the object bob up and down
// it goes 3 pixels up and down from its center position
// and it takes 100 steps to go both up and down
y = ystart + oscillate(3,100)