Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 andrew_2992 · Jul 19, 2015 at 01:05 PM · angleangleswaypointsvectors

I want to calculate angles between a series of points and find the total angle between start and finish.

Hello, this will be my first question for the unity community. I'm new to Unity but have been programming for years. I've been conquering through, trying to grasp multiplying rotations by other rotations by time etc and all of these new (to me) 3d programming concepts. I'm really stumped on something that seems to be a frequent issue people run into so apologies if this is answered.

I have a parent game object with a collection of child game objects. The parent will identify the children and their transform positions and draw a line to each gameobject. I want to calculate the total number of degrees in the turn.

For example, I would calculate the angle between Waypoint[1] and waypoint[2]. I,ve tried with Vector3.angle and had no success.

I've attached an image which outlines what I'm trying to accomplish. What Im looking for help on is the angle part, the list of waypoints and calculating one by one based on start turn waypoint and end turn waypoint I have coded already.

alt text

Thanks in advance!

capture.png (139.1 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 andrew_2992 · Jul 18, 2015 at 07:17 AM 0
Share

yes, at least in this case. The only other option is that they would all be counter clockwise. If there is a series of turns like an s bend then i would split it up into two turns, one covering the cw motion and the other ccw

avatar image andrew_2992 · Jul 18, 2015 at 07:18 AM 0
Share

...and yes they're also all under 90 degrees significantly.

2 Replies

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

Answer by AlwaysSunny · Jul 19, 2015 at 01:13 PM

The more you can guarantee about a situation, the easier it is to solve. Based on the diagram and comments, you have enough knowns to use a pretty simple method.

Since you're already using gameobjects for your waypoints, it would be useful to make each face its tangent in the curve. You could use LookAt() with the world "up" axis as the normal. This would allow the first element to make a meaningful contribution to the process, since otherwise it has no angular relationship to report (without additional data e.g. an imaginary previous waypoint).

Following this look-at idea, if they're coplanar, then you could sum the Vector3.Angle()s between each pair's forward directions. If not coplanar, you could zero out the "up" field of each position (or project their "forward" vectors onto the XZ plane) thus treating them as coplanar.

If you wanted the signed angle, that can be done too with a few cross and dot checks. Then you can use the same method for CW/CCW, even for "S" curves, etc, and just report the total difference in angle from start to end, or separate CW and CCW totals.

If you don't care about the start / end points making a contribution to this process (you might not), you could get the difference in position between each pair, then walk through those found vectors, comparing each to the next with Vector3.Angle.

In that case, the algorithm would take on this basic shape:
Vector3.Angle( b-a, c-b ) +
Vector3.Angle( c-b, d-c ) ...

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 andrew_2992 · Jul 21, 2015 at 02:43 AM

Just to let you guys know, and anyone else who stumbles on this article with a similar goal in mind. I've found a solution to my problem, thanks to the help from Sunny. The "look at" part you mentioned practically gave me an epiphany. It was something I had over looked completely and you were right, they had no angular relationship. Once I setup the look at for every waypoint after start turn and before end turn, to look at the following waypoint, I noticed in the angles in the inspector that they now had a relationship. I've found that Im able to find the angle im looking for by subtracting the rotation of the current waypoint from the rotation of the next waypoint in the list, who's global rotation will either be equal or greater than the current one the further down the turn it is, hence the turn lol. It's not exactly 100% elegant at all. But it completely works. I'm not a fan of doing things messy, but im going to see how this approach works, if I can keep it controlled it should do fine. So far its cooperating. Thanks for the tips Sunny.

Cheers -Andrew

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

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

2D angle of two Vec3 0 Answers

Aligning/mapping angles of Input.GetAxis(with .localEulerAngles 0 Answers

How to find direction Vector for a collision surface? 1 Answer

Working out Difference in Rotation 2 Answers

Angle between two objects' facing direction 2 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