Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Calam1tous · Sep 23, 2013 at 04:35 AM · rotationspriteangle

Angle of parametric path

Hello!

In my project I am working on I am trying to have an airplane sprite rotate as it moves along a parametric path (figure-8). I want it to always face the direction of the path, but I am having one issue with this. My parametric path is defined as:

x = sin(2t), y = cos(t)

I calculate the angle with:

angle = -1 (arcsin(dx / sqrt(dx^2 + dy^2) (180 / pi))

(where dx and dy are the changes in x and y)

However, when the parametric path crosses itself (on the up-slope and down-slope) the angle stays the same for both cases (when it should be facing ~45 degrees up going counter-clockwise and ~-45 degrees down going clockwise). This is because on the down-slope, the dy becomes negative (which would cause the angle to rotate in the negative direction), but the sign gets lost in the square root and the angle becomes positive.

I was thinking about somehow using an arccos angle instead so that the dy would be on the numerator, but I keep getting stuck.

I can't figure out how to fix this and I was just wondering if anyone (who is better at trig / math than I am :P) can help me.

Thanks!

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

1 Reply

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

Answer by robertbu · Sep 23, 2013 at 05:24 AM

Given dx and dy, you can use Mathf.Atan2() to calculate an angle. It would be Mathf.Atan2(dy, dx), and if you were working on the XY plane, the reference would be Vector3.right. I'm not sure how you are using this angle, so you may have to make adjustments to get the angle in the form you desire. Another solution is to turn dx and dy into a Vector. Then you can get the signed angle between this vector and any reference vector. Here is one of references for signed angles between two vectors:

http://answers.unity3d.com/questions/181867/is-there-way-to-find-a-negative-angle.html

My other reference is not coming up (Internal Server Error), so search in a bit for "unity3d signed angle vectors" if you want other solutions.

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 Calam1tous · Sep 23, 2013 at 03:07 PM 0
Share

This worked! I thought I had tried using ATan2 before, but I guess I did something wrong. Thanks!

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

16 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

Related Questions

Rotate angle between two points 0 Answers

How to calculate angles and apply to rotate an object. 1 Answer

Rotating sprite through touch (storing current rotation) 0 Answers

Convert player input to angle/rotation? 1 Answer

Add Force to the right of the rigidbody, not right of the screen 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