- Home /
Move object to position with keypress
Hi all.
I am trying to demonstrate how an object is assembled and would like to move an object slowly to a certain position with a key press. And slowly move it back if i press the key again.
Could i maybe modify this Hide/Show object on key press script to do that?
Answer by misher · Oct 20, 2020 at 08:53 AM
You can achieve this using at least 2 approaches: using animation or moving object with code. I will describe the second method. In your Update method, on key down, you can switch between 2 different points: somethinbg like opened/closed positions. Then move your object using Vector3.MoveTowards static method to the target point by a certain distance eache frame (each Update call).
Can you elaborate? I had help with the script above, since i am a rookie at program$$anonymous$$g.
I have been looking at a few tutorials about moving object using vector3 but none the wiser on how to specify moving distance or moving position of an object.
$$anonymous$$e = Basic Af i know :o
Your answer
