Camera Movement with Mouse – Unity3D (C#)


Camera Movement with Mouse – Unity3D (C#)

This type of camera controller is mostly used in RTS projects. You can move camera with mouse movement. There are two types of camera movement with mouse: Touch the edges of screen or drag the mouse.

In “Drag the Mouse” movement type, player holds right mouse button and drags the mouse to move camera view.

In the second camera movement type, player drags the cursor to edges of the screen. There are four edges so, we should check four possibilities.

Both solutions are pretty good, you can use whichever you want.

©Coffee Break Codes – Camera Movement with Mouse – Unity3D (C#)


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Camera Movement with Mouse – Unity3D (C#)

  • Alex

    Thanks for the code! I would add a = in one of the IF so that we are still translating the camera when the user drags vertically (Mouse X displacement can be 0). Otherwise drag behavior is choppy.

    … (Input.GetAxis (“Mouse X”) <= 0) …