- Home /
How can I create an offset for the values of a sine wave over time.
Hi, I have a script that moves a rigidbody up and down over time although I would like to be able to create an offset of the position between multiple rigid bodys so that they're not all moving along at the same height/position in the sine wave.
Where would I add the timingOffset value into this script?
var height = 2.0;
var speed = 2.0;
var timingOffset = 0.0;
function Update ()
{
var push = (Mathf.Sin(Time.time * speed )) * height;
rigidbody.velocity = Vector3(0, push, 0);
}
Thanks!
Comment
Best Answer
Answer by Evil-Dog · Jul 18, 2011 at 07:16 PM
you would add
function Awake()
{
timingOffset = Random.value * (Mathf.PI / 2);
}
and change
function Update ()
{
var push = (Mathf.Sin((Time.time + timingOffset) * speed )) * height;
rigidbody.velocity = Vector3(0, push, 0);
}