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
2
Question by WilliamBang · May 20, 2016 at 06:23 PM · mousecamera rotatedraggingmouse positionmouse-drag

Click and drag to rotate camera, like a pan?

Hello,

For an application I am trying to make a first person camera that rotates around it's own axis to look around, so the camera stands still. To rotate the camera/view around the user would move the mouse somewhere on the screen, click and then drag to move the camera. Exactly the same way that Google Street View handles it.

link to street view example: https://www.google.dk/maps/@55.708028,12.5625901,3a,75y,0.64h,80.48t/data=!3m7!1e1!3m5!1sdAX8QU2SY5-KDRQ-uKNAEA!2e0!6s%2F%2Fgeo1.ggpht.com%2Fcbk%3Fpanoid%3DdAX8QU2SY5-KDRQ-uKNAEA%26output%3Dthumbnail%26cb_client%3Dmaps_sv.tactile.gps%26thumb%3D2%26w%3D203%26h%3D100%26yaw%3D69.886124%26pitch%3D0!7i13312!8i6656

I am new to coding more advanced languages involing vectors, quaternions and what not, and I understand that some of what needs to happen is to calculate distances and differences between the mouse starting position and moving position in relation to the camera, but I am having a difficulty wrapping my head around it all?

I have looked and looked for others trying to do the same very few came up, and none yielded any results.

Any help and or suggestions on where to find some information, would be much apprecieated.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Marlon_Braga · Jul 06, 2017 at 10:01 PM

This work for me

Just attatch on Camera

 using UnityEngine;
 
 public class StreetViewCamera:MonoBehaviour {
     public float speed = 3.5f;
     private float X;
     private float Y;
 
     void Update() {
         if(Input.GetMouseButton(0)) {
             transform.Rotate(new Vector3(Input.GetAxis("Mouse Y") * speed, -Input.GetAxis("Mouse X") * speed, 0));
             X = transform.rotation.eulerAngles.x;
             Y = transform.rotation.eulerAngles.y;
             transform.rotation = Quaternion.Euler(X, Y, 0);
         }
     }
 }
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 KacobJeith · Oct 17, 2017 at 10:31 PM 0
Share

This works great in the Unity Editor. What would the equivalent look like if using a touch screen?

avatar image
0

Answer by FortisVenaliter · May 20, 2016 at 06:24 PM

You should check out the MouseLook script in the Standard Asset FirstPersonController. What you're describing is virtually identical... you'd just need to check if the mouse button is down to activate it.

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 WilliamBang · May 21, 2016 at 01:50 PM 0
Share

Thanks so much for a response! I found the $$anonymous$$ouseLook script you were talking about, but I can't attatch the script to anything, it gives me an error of "Can't add script, needs to be derive of $$anonymous$$onoBehaviour" I don't know which parts of the script to alter. I assume some of the declarations in the beginning of the script needs to be change, so it becomes a derive of $$anonymous$$onoBehaviour?

avatar image FortisVenaliter WilliamBang · May 21, 2016 at 03:05 PM 0
Share

If you intend to use it as one, yes. Or you can use it as a subcomponent of another script like FirstPersonController. It's entirely up to you how you code your game.

avatar image WilliamBang FortisVenaliter · May 21, 2016 at 05:27 PM 0
Share

Okay, I have added : "$$anonymous$$onoBehaviour" to the public class $$anonymous$$ouseLook. Then I have attatched the script to my $$anonymous$$ain Camera, but no mouse movement is registered when moving the mouse, I haven't tried to implement any Get$$anonymous$$ouseButtonDown, first I wan't to see if I can get the $$anonymous$$ouseLook script to work on it's own, but I can't. I assume just adding the $$anonymous$$onoBehaviour doesn't work? Perhaps it's dependent on a character controller or something like that?

Show more comments
avatar image
0

Answer by hydrix · Sep 22, 2016 at 09:09 PM

 Camera.main.transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X")*rotateSpeed, 0), Space.World);

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

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

7 People are following this question.

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

Related Questions

getting maximum x and y values of mouse position 1 Answer

How to detect how much was mouse moved only horizontaly? 1 Answer

How to Instantiate from mouse pos? 0 Answers

Camera controls not working quite right 0 Answers

Object Rotate with Camera 2 Answers


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