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 /
This question was closed May 27, 2016 at 11:58 AM by Poetepoet for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Poetepoet · May 26, 2016 at 01:05 PM · c#unity 5camera rotate

Make continuous camera rotation whilst holding the RMB

Hello everyone!

I am a complete beginner in Unity C# programming, I'm learning it to complement my skill in my game design course. I am currently working on a script to control the camera, so far I've achieved keyboard input with the standard WASD keys and zooming with the scroll wheel, but now I'm bumping into an issue I can't seem to resolve.

I'd like to rotate the camera following mouse movement (much like the standard asset First Person Controller) but only when the Right Mouse Button is held down. This is what I have so far:

Note: I have removed camera control code that is not relevant to the rotation for legibility purposes

 using UnityEngine;
 using System.Collections;
 
 public class CameraControl : MonoBehaviour
 {
     public float rotateSpeed;
 
     // Update is called once per frame
     void Update()
     {
         float mouseX = Input.GetAxis("Mouse X") * rotateSpeed;
         float mouseY = Input.GetAxis("Mouse Y") * rotateSpeed;
 
         //Camera can be rotated only if the right mouse button is held down
         if (Input.GetMouseButtonDown(1))
         {
             Debug.Log("Detected Right Mouse button");
             transform.RotateAround(transform.position, transform.right, -mouseY);
             transform.RotateAround(transform.position, Vector3.up, mouseX);
         }
     }
 }
 

Now, the problem I am having is that the rotation is not continuous. The only way this works is to move the mouse, click RMB once and it will snap to the new rotation. I'd like it to follow mouse movement. Can anyone help me with the code and maybe explain what they did? Thanks!

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 Poetepoet · May 27, 2016 at 11:57 AM 0
Share

A fix has been found:

I used Input.Get$$anonymous$$ouseButtonDown(1) which only detects on the frame itself, it's not a state detection. Use Input.Get$$anonymous$$ouseButton(1) ins$$anonymous$$d!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

175 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text that always looks at you 1 Answer

C# 360 Orbital Camera Controller (Gimbal Lock Issue) 1 Answer

uNet FPS Camera Error [C#] [Unity 5] 2 Answers

The location of the object by points 0 Answers

How to add a " Achievement unlocked " text and a collectible after completing all objectives 0 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