0
\$\begingroup\$

How can I change a rotation and a position of the camera smoothly when a button is clicked in Unity?

I do not want to use Update function to implement this and I do not have a GameObject or Transform which it should look at, rather I want to tweak everything manually.

I would like to see the approach using C#.

\$\endgroup\$
  • \$\begingroup\$ We'll need some more details about what you want the camera to do. You say you want to "tweak everything manually" — what specific manual inputs do you have in mind? (eg. position / orientation keyframes? A sequence of relative moves & rotations?) Also, can you describe why you don't want to use an Update function for this? Is it "Update" specifically that you want to avoid? (eg. would a coroutine executing once each frame be suitable, or is there some other constraint in play?) \$\endgroup\$ – DMGregory Sep 5 '17 at 16:30
  • \$\begingroup\$ @DMGregory, thank you very much for the attention. I solved my problem by recording an animation and then playing it on a button click. Now I have another problem, I need to record more than one distinct animations for the camera and I do not know how to do that. \$\endgroup\$ – hellomates Sep 5 '17 at 16:57
  • \$\begingroup\$ @DMGregory, okay. I solved the second problem as well. I clicked the name of the animation above properties in the animation tab and chose another animation. \$\endgroup\$ – hellomates Sep 5 '17 at 16:59
0
\$\begingroup\$

Instead of manually moving camera it was easier for my just to use Unity`s built in feature to record an animation. It is pretty straightforward, I just clicked on camera in upper tab chose Window and opened Animation tab, next I clicked to add a new animation. When the location for the new animation was specified I pressed red circle in Animation tab to record my camera. There is such long bookmark symbol in Animation tab it adds a key frame. I added it at the beginning, having my camera in initial position and at the end, moving my camera to the final position. Then I stopped recording by again pressing red circle in Animation tab. Here my animation was ready and the only thing I should have to do was to use my knowledge of animating in Unity.

Then I got a problem of needing to create more than one animation with the same GameObject. It was easy tackled by just clicking on the name of the current animation under red circle button in Animation tab and choosing created beforehand blank animation and filling it with the content I needed.

\$\endgroup\$
  • \$\begingroup\$ First or all, if that's the best answer, mark it as the selected answer (it's also a good idea to vote up comments which are really helpful or insightful). Secondly, you should read about LERP and SLERP. I don't think playing an animation is the best choice in terms of performance, if you can achieve the same result just lerping. \$\endgroup\$ – jjimenezg93 Sep 6 '17 at 3:55
  • \$\begingroup\$ @jjimenezg93, why do you think that playing an animation is inefficient decision in comparison with LERP and SLERP? \$\endgroup\$ – hellomates Sep 6 '17 at 9:39
  • \$\begingroup\$ @jjimenezg93, as far as I know I can not vote up comments. I can just mark them for the attention of the moderator. \$\endgroup\$ – hellomates Sep 6 '17 at 9:39
  • \$\begingroup\$ Basically I know what I'm doing when I'm using LERP. When animating, I haven't checked the depths of Unity to see what's beeing done, but there's probably more than that. If animation system changes at any point, performance can vary unexpectedly, right? It's pretty much unlikely math implementation changes and if it did, I bet performance wouldn't go worse. Besides that, you can use 1 script (or better, 2) to move/rotate smoothly, parameterizing it and being able to apply that same script to other objects with different parameters. I'm OFC assuming they are simple movements. Regards \$\endgroup\$ – jjimenezg93 Sep 7 '17 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.