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
0
Question by danipren · Jan 07, 2015 at 08:28 PM · explaindetermine

How to determine degrees of one object to another

hey everyone another one thats been bugging me its probably really simple but i cant find a way of working it out so any help would be appreciated.

k now i hope to explain this properly

object A will be moving and rotating constantly, say object A's forward would be 360/0 degrees on the y axis, right would be 90, behind would be 180

now my problem is determining at what degrees object B is to Object A?

probably badly explained so i drew a picture to help lol alt text

iwonder.jpg (18.7 kB)
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 Victory Dan Greene · Jan 07, 2015 at 08:44 PM 0
Share

Find A and B's positions in world coordinates ptA and ptB.

If you're working in 3 dimensions, you'll need to project ptA and ptB onto a common plane.

The vector from A to B aToB is given by ptB – ptA.

Find the facing of A aFacing by using one of its transform's axes (for example A.transform.forward), optionally rotated however you like.

The angle you're looking for is then just Vector3.Angle( aFacing, aToB ).

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 07, 2015 at 08:40 PM

Use http://docs.unity3d.com/ScriptReference/Vector3.Angle.html

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 Ed unity · Jan 07, 2015 at 08:44 PM

Using ObjectA.Forward and the vector between ObjectA and ObjectB (B.Position - A.Position) you can find the Angle between using Vector3.Angle()

More information can be found at the below answer page: http://answers.unity3d.com/questions/317648/angle-between-two-vectors.html

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 danipren · Jan 07, 2015 at 09:04 PM

thanks for your help ok ive tried this

so basically i have

 var ptA = transform.position;
     var ptB = referenceCamera.transform.position;
     var Diferance = ptB - ptA;
     var aFacing = ptA.forward;
     FinalAngle = Vector3.Angle(aFacing,Diferance); 

now this does work but not properly, im probably doing something wrong but the angle is also changing when the distance between the 2 objects change distance to each other. for examble when the are close and one goes around the other it wont go below 20 but if i go far out it will go below zero .

what im trying to achieve is that when object b is between (for example) 90 degrees and 180 degrees do something, 180 degrees to 270 do something else , 270 to 360 etc etc

thanks again and much appreciated

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 theratboy · Jan 28, 2021 at 05:57 PM 0
Share

I'm also facing a similar problem, did you ever figure out how to make it work at any distance?

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

28 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

Related Questions

How to do spherecast? 1 Answer

Why do we use the "transform." in hit.transform.gameObject.tag? 1 Answer

What are these things doing in C#? 3 Answers

how to use EditorGUI.IntField 1 Answer

Determine global movement of gameObject 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