Hi guys,
I’m trying to make a platform that moves back and forth but it seems that my struggles are useless. can anyone suggest a script in which a platform ( i.e. a box ) goes back and forth in a loop?
A simple way would be something like this…
public float elevatorHeight = 10;
void Update() {
Vector3 position = transform.position;
position.y = Mathf.PingPong(Time.time, elevatorHeight);
transform.position = position;
}
That would move it continually between y=0 and 10. A more flexible way would be to cache the initial position and ping pong an offset from that.
A slightly nicer thing would be to slew the position towards the target so that it slows down as it approaches, though that’s a bit more complicated.