Wednesday, May 27, 2015

unity - How is this rotation done?


There is a video here that shows how the camera rotates around Leon. The camera rotates around Leon in a circle, this is not difficult, but I don't understand the timing logic.


Once given a short push, the camera keeps rotating for a few more milliseconds.


If the camera would only be rotated during the real mouse movement, the camera would not keep rotating a bit after there is no more mouse movement.


However, in this video, the camera rotates a few more milliseconds even after the last mouse movement.


How could this be accomplished?



Specifically, I would like to ask if somebody can tell me if the developers add some extra movement in the direction of the mouse movement which they then "smooth out", or if they "smooth out" the end of the user's mouse movement.


Thank you!



Answer



Implementing this sort of momentum in camera motion (or really just about anything) can be done with easing functions.


When the actual input to the camera movement system stops, you have (or can compute, depending on your implementation) the speed at which the camera was rotating during the input period. Rather than simply set that speed to zero, jerking the camera to a halt, you apply some sort of easing function to slowly reduce that speed to zero, resulting in the gradual settling you see in the video.


This can be done fairly straightforwardly by adding a new state to your camera. Previously you had two states, explicitly or implicitly: moving and stopped. Add a third state, "settling." You can do this as simply as adding a "settling time left" field to your camera that is zero normally, but which you set to a non-zero value representing the number of seconds the camera takes to smoothly come to stop. Implicitly when this value is non-zero the camera is in the "settling" state.


Then, every update, if the camera is settling, keep it moving based on whatever easing function you've chosen and the time remaining, deduct from the remaining time, and there you are.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...