Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Inan-Evin · Aug 11, 2017 at 07:32 AM · cameramouse

how to make camera move with the mouse cursors

Hello everyone, i searched this but couldn't find the answers i want. The camera doesn't moves with the mouse cursor, i need to make it look where the mouse cursor is, i could find this which is closest to my question :

http://answers.unity3d.com/questions/10006/mouse-camera-camera-mouse.html

but it's about camera position, when i do that to my camera it goes too far somewhere in the scene, i just want camera to look where the cursor is.

Please help,:).

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image toddisarockstar · May 05, 2017 at 01:33 AM 0
Share
                 GameObject mycam = GameObject.Find("$$anonymous$$ain Camera");
                 Vector3 mou;
                 float senc=1f;
                 //put this in update function
                 mou=new Vector3(Input.GetAxis ("right x"),Input.GetAxis ("right y"),0);
                 mou=mou*senc*Time.deltaTime;
                 mycam.transform.position+=mou;

6 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by fffMalzbier · Jul 27, 2011 at 12:02 PM

Whats about a simple script on the camera? Just something like:

         Camera mycam = GetComponent<Camera>();
         transform.LookAt(mycam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, mycam.nearClipPlane)), Vector3.up);

(hope it work cant proof it on this mac , its CSharp by the way)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Damastasam · Sep 23, 2016 at 07:28 PM 0
Share

Can you do this for a 2D game?

avatar image Oshoura · Apr 21, 2017 at 07:31 PM 0
Share

is there a way to decrease the sensitivity a bit. I can't really control it.

avatar image joeranbenker · May 04, 2017 at 08:27 PM 0
Share

@Oshoura To control the sensitivity you can use the following code

 Camera mycam = GetComponent<Camera>();
 
 float sensitivity = 0.05f;
 Vector3 vp = mycam.ScreenToViewportPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, mycam.nearClipPlane));
 vp.x -= 0.5f;
 vp.y -= 0.5f;
 vp.x *= sensitivity;
 vp.y *= sensitivity;
 vp.x += 0.5f;
 vp.y += 0.5f;
 Vector3 sp = mycam.ViewportToScreenPoint(vp);
 
 Vector3 v = mycam.ScreenToWorldPoint(sp);
 transform.LookAt(v, Vector3.up);

I am new to Unity, so there is maybe a better way of doing it.

avatar image RavenThunderclaw joeranbenker · Mar 19, 2018 at 09:02 AM 0
Share

Is there some way to stop the camera movement after it has reached some set threshold in all directions. Like if I want my camera not to look straight down or in the back?

avatar image
2

Answer by Nexnar · Jul 26, 2018 at 02:53 AM

@rifintidhamar I agree, just as rifintidhamar first implied(and to my elaboration) there are multifaceted approaches and the current method presented can be scrubbed a bit, I suggest a GetAxis Cross Scew

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rifintidhamar · Jul 27, 2018 at 06:01 PM 0
Share

while its clearly not perfect, i found it much more use able than what we currently have for something like a mouse, tell me what you think.

     float mouseX = (Input.mousePosition.x / Screen.width ) - 0.5f;
     float mouseY = (Input.mousePosition.y / Screen.height) - 0.5f;
     transform.localRotation = Quaternion.Euler (new Vector4 (-1f * (mouseY * 180f), mouseX * 360f, transform.localRotation.z));
avatar image
0

Answer by OLIISKING · Nov 13, 2015 at 01:52 PM

@fffMalzbier you are missing a ")" in your code. :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fffMalzbier · Nov 13, 2015 at 02:01 PM 0
Share

Good catch , I updated the code.

avatar image
0

Answer by JaackFord · Jan 22, 2018 at 11:51 PM

@joeranbenker where is that code supposed to go? update or start?,@joeranbenker Where is that sensitivity code supposed to go? which method? Cause right now that changes nothing for me.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Arkei · Jan 23, 2018 at 09:55 AM 0
Share

Update ofcourse. if you put it in start, it will only work the first frame of the game.

avatar image
0

Answer by rifintidhamar · Jul 25, 2018 at 08:42 PM

this method is really only useful for a joystick, and even then, using the get axis method is probably a better idea.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make the camera rotate around the player and face the player. 1 Answer

Please help me with my mouse pointer 0 Answers

Gaining the Z value in ScreenToWorldPoint().. newbie here,How do i get the z distance in ScreenToWorldPoint().. noob here 0 Answers

CATCH MOUSE CLICK EVENT ON OBJECTS 0 Answers

Rotate towards mouse pointer 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges