- Home /
how to let the camera follow the mouse
currently i am creating an rts game. i have a hard time in making the camera follow the mouse pointer when i move it. Can you please help me?
In order to point you at the right material or answer the question we need to know some more details. By follow the mouse do you mean follow by position, or follow by rotation? The mouse is 2D, but you are looking into a 3D world, so you also have to deter$$anonymous$$e "following the mouse at what distance in front of the camera. Or perhaps you want to follow the mouse as it intersects with objects in the scene? And how does what you want compare with the standard '$$anonymous$$ouseLook' script provided by Unity?
It depends on what you are trying to achieve with the camera following mouse. For e.g. if u are making a first person shooter, you would have to make the camera act as human eyes looking around and rotating around a single point.
Please let me know about what you are trying to achieve by making the camera follow mouse.
Answer by Valentin_B · Jan 20, 2014 at 10:49 AM
If your view is classical rts camera (screen scrolling when the mouse pointer reaches the borders of the screen), then you need to use Input.mousePosition it will give you a vector3.
x and y are the coordinates of your pointer, you just need to know that the bottom-left of the screen or window is at (0, 0). The top-right of the screen or window is at (Screen.width, Screen.height).
else, if for some reason you're making a rts with the camera always centered on the mouse, you simply need to use Input.GetAxis("horizontal") and Input.GetAxis("vertical")
Your answer
![](https://koobas.hobune.stream/wayback/20220613130920im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity3d RTS style camera movement is jittery 0 Answers
RTS camera 1 Answer
Making an RTS camera 1 Answer
Error about Camera panning. 0 Answers
clamping camera movement to map size and camera corners 0 Answers