- Home /
Move forward and back an object
How can I make an object move forward for 5 seconds and then 5 seconds back, without never stopping ?
Comment
Try using the PingPong function to add a ~pingponging~ constant to some position.
You will need to save the starting position or give it the central point to move back and forward from:
private var origin : Vector3;
var distance : float = 5;
var speed : float = 1;
function Start(){
origin = transform.position;
}
function Update () {
transform.position = origin + (transform.forward*($$anonymous$$athf.PingPong(Time.time*distance*speed + (distance*speed/2), distance*2)-distance));
}
Your answer
Follow this Question
Related Questions
Clipping a line to a rect? 1 Answer
Audio clip length not equal than wav length 0 Answers
Animating clip with transitions 2 Answers
animation clip wont play 1 Answer
Transferring animation clips 0 Answers