Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Chinmay_Gawande · Jun 21, 2019 at 09:36 PM · vector3gameobjectscoordinatesangles

Setting Vector3.angle between two gameObjects

So here is the question: I am able to get an angle between two gameObjects by using Vector3.angle

 public Transform target;
 void Update()
 {
     Vector3 targetDir = target.position - transform.position;
     float angle = Vector3.Angle(targetDir, transform.forward);
 }


but the real problem is that I want to set this angle to another two gameObjects which are at different positions and angles in world space...........

Thank You

(I am sorry but i was not able to upload images because i am getting a disgusting error in unity answers which says - Error parsing the uploaded file.)

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 ShamimAkhter · Jun 21, 2019 at 10:18 PM 1
Share

float angle = Vector3.Angle(targetDir, transform.forward);

Well this is actually angle between transform.forward and the other game object. And you cannot have angles between two objects. You need three objects.

avatar image ShamimAkhter · Jun 21, 2019 at 10:21 PM 0
Share

However if you need to set the angle between your current gameObject and

another two gameObjects

then that can be done. Tell me if that's what you need.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chinmay_Gawande · Jun 21, 2019 at 10:34 PM

@ShamimAkhter Yes, I know that it is the angle between transform.forward of the gameobject at which the script is attached and the other one. I want the same angle between the 3rd gameobject's transform.forward with 4th gameobject. I know it seems complicated but I have a graphical representation of the same but I am not able to upload it due to the error.

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 ShamimAkhter · Jun 21, 2019 at 10:57 PM

Ok. You need to rotate your 3rd_gameObject so as to make the angle between its forward and 4th_gameObject equals to "angle".


Lets find the rotation axis. You can do it using: Vector3.cross(3rd_gameObject.transform.forward, targetDir); where targetDir will be (3rd_gameObject.position - 4th_gameObject.position).


Then rotate your 3rd_gameObject: 3rd_gameObject.transform.rotation = Quaternion.AngleAxis(angle, rotationAxis)

Comment
Add comment · Show 2 · 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 ShamimAkhter · Jun 21, 2019 at 10:59 PM 0
Share

Tell me if you need code.

avatar image Chinmay_Gawande · Jun 22, 2019 at 01:34 AM 0
Share

@ShamimAkhter it would be great if you will share it !

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

136 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

Related Questions

How to use spherical coordinates in unity? 0 Answers

How to detect if player is facing towards enemy's back 2 Answers

Vector 3 moves object to wrong location? 2 Answers

Need help setting a vector behind a character 1 Answer

Obtain angle from given rotation 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