How do I get an object back to its starting position in Unity?

0

I have an object that is reached by raycast and use   cObj.transform.position = Vector3.MoveTowards(cObj.transform.position,main.transform.position, step); for the object to go against the camera.

How do I get him back to his starting position? I have a button that when focusing the image back from where it came.

    
asked by anonymous 02.03.2016 / 20:00

3 answers

1

Look, I would store the initial position in a variable and when it was hit it loaded transform position by setting the values that were set in the variable.

Maybe it's a more practical way, but I'd do it that way

    
02.03.2016 / 20:04
1

I created a variable with the initial position between the camera and the object that you want to move and then to return to the original position you would do:

var posicao_inicial =  new Vector3(3,3,3);


cObj.transform.position = Vector3.MoveTowards(cObj.transform.position, main.transform.position-Vector3.Distance(cObject.position, posicao_inicial), step);

I have not been working with Unity for some time, nor can I test here, but I think something within the genre will work.

    
02.02.2017 / 15:51
0

Julia, create an ex variable. Vector3 initial position , to save the position, then in the Start method place Initial position = transform.position;

When you want it to go back to its initial position, you use: transform.position = initial position;

    
28.04.2016 / 02:22