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 Scorpion2018 · Mar 05, 2020 at 09:37 PM · rotationrotaterotate objectcircle

Advance Unity 2d apply circle Rotation-z with mouse

Sorry I'm new to this, I am trying to rotate a circle from A to B with mouse.position, but I would like that the next time I receive a new mouse.position the circle rotates in z from the last position (B) to C, can someone help me ? Thanksalt text current code:

     Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(transform.position);
 
         
         Vector2 mouseOnScreen = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition);
        
        
         angle = AngleBetweenTwoPoints(positionOnScreen, mouseOnScreen);
 
         
 //apply Rotation
         transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
 
 
         float AngleBetweenTwoPoints(Vector3 a, Vector3 b)
         {
             return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
         }

atob.png (5.6 kB)
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 tormentoarmagedoom · Mar 06, 2020 at 12:58 PM 0
Share

CAn you explain what "next time I receive a new mouse.position the circle rotates in z" means?

In Z what? give reference

avatar image Scorpion2018 tormentoarmagedoom · Mar 06, 2020 at 01:55 PM 0
Share

Sorry i didn't explain well, so i'm trying to rotate the circle in transform.rotation.z, and i can with this code, the problem is that when i rotate the circle again(click with mouse again) it directs the object to the mouse position (recognizes the mouse position as direction to start position to the next position) ins$$anonymous$$d of rotating from last position to the mouse position.

here is the video: https://takeafile.com/?f=rixukecagi

1 Reply

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

Answer by tormentoarmagedoom · Mar 06, 2020 at 02:08 PM

Hello.

You just need to apply your last rotation every time. So every time you rotate, need to store its final rotation for the next time:

  transform.rotation =  LastRotation + Quaternion.Euler(new Vector3(0f, 0f, angle));
  LastRotation = transform.rotation;

Bye !

Comment
Add comment · Show 6 · 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 Scorpion2018 · Mar 06, 2020 at 02:38 PM 0
Share

Thanks by the answer, but is giving error...

alt text

error.png (25.0 kB)
avatar image tormentoarmagedoom Scorpion2018 · Mar 07, 2020 at 08:44 PM 0
Share

$$anonymous$$y answer was not code, was just n "structure. You need to SU$$anonymous$$ Euler angles!

 LastRotation = transform.eulerAngles

avatar image Scorpion2018 tormentoarmagedoom · Mar 11, 2020 at 01:58 PM 0
Share

It works!! thanks a lot!!

transform.rotation = Quaternion.AngleAxis(angle - startAngle, Vector3.forward);

avatar image TreyH · Mar 06, 2020 at 04:11 PM 0
Share

I think you meant to multiply the quaternions, but the order would be off for that too

avatar image Scorpion2018 TreyH · Mar 06, 2020 at 05:37 PM 0
Share

I tried, but thanks.

avatar image Scorpion2018 · Mar 06, 2020 at 05:39 PM 0
Share

I think its not that easy....

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

163 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

Related Questions

How to rotate an object according to the camera's view? 1 Answer

Player Arm will not rotate when moving with Xbox Joystick 1 Answer

gameobject stops moving correctly when rotating 1 Answer

Smooth Camera Rotation After 2 Seconds 1 Answer

Wonky Camera Behaviours 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