Droping a box by pressing space or any key
Hello ! I'm stuck at this part of my game. How can i drop a box by pressing space or any key and then returned into the same place that was initially.
When posting such questions you need to show your research and what you have currently attempted.
This question is a 'reject' even in the help-room.
Next time, perform searches and try something first.
But really, you need to hit the tutorial section.
Answer by NonBreaker · Apr 04, 2016 at 04:34 PM
I'm thinking you'll need to watch for a key press, then use something like Lerp() to move it on the y-axis. I'm not exactly a code guru and am fairly new to Unity, so hopefully this at least points you in the correct direction.
if ( Input.GetKeyDown(KeyCode.Space)){
transform.position = Vector3.Lerp(transform.position, target.position, speed)
}
I believe that will move it initially, then you would just need to run another Lerp() to get it back to the original location (if you need the motion to be smooth - if not, just update the transform.position.y property and it should snap back to the original location.
Sincerely hoping this helps, NonBreaker
Edited for spelling
Your answer
Follow this Question
Related Questions
Car movement left or right 0 Answers
Need help with GameObject placement 2 Answers
Survival shooter enemy not taking damage 0 Answers