Moving camera with the mouse left and right

Hi, is it possible, if our canvas or our background is bigger than our camera view (it surpasses it horizontally), to place our mouse on the right or left side of our screen and make the camera move into that direction? I would like that the movement happens only in certain areas near the edge, and not to react in the middle, for instance. Also, would like to be able to control the speed of the movement. Is this possilbe in Unity, and if so, how would you go about doing something like that?

Yes, you’d do this with Camera.ScreenToViewportPoint and Input.mousePosition.

Vector3 viewportPos = Camera.main.ScreenToViewportPoint(Input.mousePosition;

Then just check viewportPos.x, it should now be a number between 0 and 1. You can then move left if it’s smaller than for example 0.1 and right if its bigger than 0.9.

1 Like

Thanx for the info, will write here if there are some problems.