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 graiderzs · Nov 20, 2015 at 07:18 AM · c#camerapivotangleaxis

Moving an object slower, in clockwise motion, around a pivot with Quaternion.AngleAxis

Hello Everyone, pls pls pls help me..

I want my object to move in clockwise motion at a slower speed, when I click, hold and drag my mouse in clockwise motion, around a pivot.

I already managed to do it, at full speed, but not at a slower speed.

When I try to make it move slower, the object does move slower, but halfway through the movement, it will go back to where it starts.

For example, when ....

Normal speed = Full clockwise motion

Slow speed = Half clockwise motion (after reaching the end of the half clockwise motion, it will go back to where it starts (I'm not sure)).

.

Here is the code, "target" is my pivot.

If I take out, ( ang = ang / 2; ), object is able to move clockwise motion at full speed.

     void Update () {
 
         //360 DEGREE
         if (lastAngledifference < -180)
         {
             lastAngledifference = lastAngledifference + 360;
         }
         if (lastAngledifference > 180)
         {
             lastAngledifference = lastAngledifference - 360;
         }
 
         //calculate distance
         if (Input.GetButtonDown("Fire1"))
         {
             angleDifference = 0;
         }
 
         if (Input.GetButtonUp("Fire1"))
         {
             lastAngledifference = lastAngledifference + angleDifference;
         }
 
  if ( (canPlay) && (canStart) && (!twofingers) )
         {
             if ((Input.GetButtonDown("Fire1")))
             {
                 //mouse position at start, and calculate angle
                 touchPoint = Camera.main.WorldToScreenPoint(target.position);
                 touchPoint = Input.mousePosition - touchPoint;
 
                 deltaAngle = Mathf.Atan2(touchPoint.x, touchPoint.y) * Mathf.Rad2Deg;
             }
 
         if ((Input.GetAxis("Mouse X") < 0) || (Input.GetAxis("Mouse X") > 0) || (Input.GetAxis("Mouse Y") < 0) || (Input.GetAxis("Mouse Y") > 0))
             {
                 //mouse position when moving, and calculate angle
                 pt = Camera.main.WorldToScreenPoint(target.position);
                 pt = Input.mousePosition - pt;
 
                 ang = Mathf.Atan2(pt.x, pt.y) * Mathf.Rad2Deg;
 
                 ang = ang / 2;
 
                 angleDifference = deltaAngle - ang;
 
                 v = Quaternion.AngleAxis( (lastAngledifference + angleDifference)  , Vector3.forward)  * (Vector3.right * fRadius);
 
                 transform.position = target.position - v;
 
             }
         }
     }

Code Explanation:

  • I calculate the angle of mouse from pivot

-DeltaAngle, is calculated, when I left clicked DOWN. It calculate the angle of the mouse from pivot.

-ang, is calculated, when I left clicked HOLD, it calculate the angle of the mouse from pivot.

-angleDifference, is the angle difference of, (DeltaAngle and ang).

-Then, I move my object to angleDifference.

-lastAngledDifference, is so that, I am able to resume the clockwise motion if I stop at any point of time.

-(Vector3.right * fRadius) is how far is the object from the pivot.

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 Le-Pampelmuse · Nov 20, 2015 at 09:00 AM 0
Share

Please read the Frequently Asked Questions and the User Guide.

  • Your question is not formatted properly.

  • Your question is not very descriptive: It is not clear what you try to do.

Do you want to drag (move) an object with the mouse?
Do you want to rotate an object with the mouse?

If yes, then you should google it, there is enough information about those topics. Also, you already asked this here.

If no, then be more specific and format your text properly using the tools.

What issue are you describing with

$$anonymous$$oving an object around a pivot with Quaternion.AngleAxis

This is a rotation vector, you can't move something with a rotation.

If something already works at "full" speed, then it will work at any speed. It depends on what you do with that speed.

One tip for you:

 if ((Input.GetAxis("$$anonymous$$ouse X") < 0) || (Input.GetAxis("$$anonymous$$ouse X") > 0) || (Input.GetAxis("$$anonymous$$ouse Y") < 0) || (Input.GetAxis("$$anonymous$$ouse Y") > 0))
 {}

..is not very efficient, basically you say "if the X or Y input is not zero":

 if(Input.GetAxis("$$anonymous$$ouse X") != 0 || Input.GetAxis("$$anonymous$$ouse Y") != 0)
 {}

..this also is easier to read and check for errors ;)

Have a nice day.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

When playing builded version of game the cameras only captures part of scene. 0 Answers

Zoom camera 1 Answer

Camera Jitters When Displacing and Rotating Smoothly 0 Answers

How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers

How to script a random asset generator> 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