-1
\$\begingroup\$

For clarification: I don't need to know how to rotate the camera. What I'm asking instead is how the movement of the camera AFTER the mouse move is calculated (the "slow fade out"). I've tried a lot, but it never looks right to me.

The question:

I have uploaded a video here.

This video shows a camera settling behaviour.

In this video, the mouse pointer is moved swiftly from left to right.

The camera however does not abruptly start moving to the other direction, instead it settles in the previous direction before going to the other direction.

I would like to know how this is settling is done. I have tried really much to recreate this behaviour:

Taking into account the overall speed until the next zero mouse movement, fading out the last non-zero mouse movement, just anything that I could think of.

Could anybody tell how he thinks this could be done?

\$\endgroup\$
  • \$\begingroup\$ Look into Cinemachine, its a package from Unity that has the ability to achieve the behavior you are interested in. \$\endgroup\$ – Gary Holiday Feb 11 at 16:27
  • 1
    \$\begingroup\$ You might want to add what you have tried and why it did not work, this would help give answers that are more adequate to your situation. \$\endgroup\$ – Alexandre Vaillancourt Feb 11 at 17:22
  • \$\begingroup\$ Possible duplicate of How is this rotation done? \$\endgroup\$ – Gary Holiday Feb 11 at 20:03
  • \$\begingroup\$ @GaryHoliday No, this question here is more specific. \$\endgroup\$ – tmighty Feb 11 at 23:11
1
\$\begingroup\$

Have you tried Vector3.Lerp? i.e. Lerping your current position to the target position calculated by the mouse movement.

Lerp is short for linear interpolation. In this case you'd move part way to the target. The final parameter is what portion of the total distance you want to move (in this case 50%). Lowering this would get a slower camera feel. There's also Vector2.Lerp, if you're doing a 2D game.

Position = Vector3.Lerp(Position, TargetPosition, 0.5F);

https://en.wikipedia.org/wiki/Linear_interpolation

Note: I don't use Unity

\$\endgroup\$
  • \$\begingroup\$ Yes, I've tried that. What I don't understand (if I look at the video) is how it's calculated that the camera still swings to the right while some more and becomes slower while the mouse pointer is already moving the left. \$\endgroup\$ – tmighty Feb 11 at 21:12
  • \$\begingroup\$ Try changing the acceleration of the camera instead of the position? That would make sense if you want the camera to keep going. \$\endgroup\$ – gusg21 Feb 11 at 21:49
  • \$\begingroup\$ I'm setting the position of the camera directly using the mouse position. The camera itself doesn't have an acceleration. Or perhaps I don't understand what you mean. \$\endgroup\$ – tmighty Feb 11 at 23:13
  • \$\begingroup\$ I will improve my question to make the problem better to be understood. \$\endgroup\$ – tmighty Feb 11 at 23:14
  • \$\begingroup\$ I don't use Unity, so I can't really help you any more, sorry. \$\endgroup\$ – gusg21 Feb 11 at 23:42

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.