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 /
avatar image
0
Question by AnimAlu · Jun 23, 2011 at 04:44 PM · mouserotatetogglelift

Mouse Problem

I've go the following script which rotates an object in front of me as I mouse over it. However, when I lift up on the mouse button, the rotation stops. I would like the function to continue, even when I lift up. How can I do this? Here's the code:

 var speed : int;
 var friction : float;
 var lerpSpeed : float;
 private var xDeg : float;
 private var yDeg : float;
 private var fromRotation : Quaternion;
 private var toRotation : Quaternion;
 
 function Update () {
     if(Input.GetMouseButton(0)) {
         xDeg -= Input.GetAxis("Mouse X") * speed * friction;
         yDeg -= Input.GetAxis("Mouse Y") * speed * friction;
         fromRotation = transform.rotation;
         toRotation = Quaternion.Euler(yDeg,xDeg,0);
         transform.rotation = Quaternion.Lerp(fromRotation,toRotation,
                                   Time.deltaTime  * lerpSpeed);
     }
 }
Comment
Add comment · Show 2
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 Chris D · Jun 23, 2011 at 05:03 PM 0
Share

Please remember to format your code (the 10101001 button) :D

avatar image AnimAlu · Jun 23, 2011 at 05:04 PM 0
Share

Thank you Chris! I'm new here :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris D · Jun 23, 2011 at 05:07 PM

add in a boolean value to see if you've already clicked on it or not. Something like:

 var activelyRot : Boolean = false;

 function Update () {
     if(Input.GetMouseButton(0)) 
         activelyRot = !activelyRot;
 
     if(activelyRot){
         xDeg -= Input.GetAxis("Mouse X") * speed * friction;
         yDeg -= Input.GetAxis("Mouse Y") * speed * friction;
         fromRotation = transform.rotation;
         toRotation = Quaternion.Euler(yDeg,xDeg,0);
         transform.rotation = Quaternion.Lerp(fromRotation,toRotation,
                                   Time.deltaTime  * lerpSpeed);
     }
 }

This should let you click once to begin controlling it, then click again to stop it.

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

Answer by AnimAlu · Jun 23, 2011 at 05:32 PM

Not sure why, but I'm getting a compiling error when I run this. complete code:

 var speed : int;
 var friction : float;
 var lerpSpeed : float;
 private var xDeg : float;
 private var yDeg : float;
 private var fromRotation : Quaternion;
 private var toRotation : Quaternion;
 var activelyRot : Boolean = false;
 
 function Update () {
     if(Input.GetMouseButton(0)) 
         activelyRot = !activelyRot;
 
     if(activelyRot){
         xDeg -= Input.GetAxis("Mouse X") * speed * friction;
         yDeg -= Input.GetAxis("Mouse Y") * speed * friction;
         fromRotation = transform.rotation;
         toRotation = Quaternion.Euler(yDeg,xDeg,0);
         transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime  * lerpSpeed);
     }
 }
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 Chris D · Jun 23, 2011 at 05:42 PM 0
Share

In the future, please try to keep clarifications or feedback attached to the entry you're referring to. You can't comment on my answer yet (a quirk of how the rep system works here) so, in the mean time, just put comments on your question or edit your post.The answer area should be reserved for solutions.

In regards to the compile error, I apologize; I'm not somewhere I can test the code at the moment. What error are you receiving?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotate to mouse seems to be inversed 1 Answer

Rotate the player to face where the mouse is pointing 3 Answers

Rotation Question 2 Answers

Camera Rotate to mouse position -2 Answers

How to make Camera unable to move, in Mouse X 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