Hi, how do I write in code to make an object moves up and down in an axis like a sine wave? Thank you very much. http://upload.wikimedia.org/wikipedia/commons/7/77/Waveforms.svg
Hi There's a script in the 3D Platform Tutorial to handle this, search for the LaserTrap in the document. See ya
Thanks. I'm getting the object to move up and down now. But, how do I make it move in x-axis. I can't get it move in Time.deltaTime. Code (csharp): var height = 3.2; var speed = 2.0; var timingOffset = 0.0; var count=0; function Update() { count++; var offset = Mathf.Sin(Time.time * speed + timingOffset) * height / 2; transform.position = Vector3(count, offset, 0); }
The code you are using moves the object in the X axis by one unit each frame. To make it move at one unit per second, use something like this:- Code (csharp): ... var count=0.0; function Update() { count += Time.deltaTime; var offset = Mathf.Sin(Time.time * speed + timingOffset) * height / 2; transform.position = Vector3(count, offset, 0); }
Every two years someone comes across this post and is helped. Thank you for the great question, and the great answer!