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 /
  • Help Room /
avatar image
0
Question by Figgo · May 17, 2017 at 10:17 AM · positionplayerobjectvector3angle

How do i get the angle of two Vector 3's?

I'm still fairly new to Unity and C#, so this probably looks a bit sloppy. I'm working on a script that's supposed to log the angle to Vector3 (Player's position) from Vector3 b (Objects position), and I'm using Vector3.Angle, but it's not working quite like I want it to, as the angle only goes up to about 76 and then starts going back down again, and if I walk further from the object the angle shouldn't change because I don't want the distance between them to affect it, but it does for some reason.

Thanks in advance for any help.

Here's my code so far:

     public Vector3 PlaPoint;
     public Vector3 BombPoint;
 
     public Transform PlayerPos;
     public Transform BombPos;
 
     public float angle;
 
     void OnTriggerStay () {
 
         Vector3 BombPoint = new Vector3 (BombPos.position.x, 0, BombPos.position.z);
         Vector3 PlaPoint = new Vector3 (PlayerPos.position.x, 0, PlayerPos.position.z);
 
         angle = Vector3.Angle (BombPoint, PlaPoint);
 
         Debug.DrawLine (PlaPoint, BombPoint);
         Debug.Log ("Angle : " + angle);
     }

By the way the Object in question is supposed to be a bomb, thus it being called BombPos and BombPoint.

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

Answer by jdean300 · May 17, 2017 at 09:42 PM

You can't get the angle between points without a reference to something else. Vector3.Angle is used to get the angle between two directions.

alt text

So if you look at this image, we can get the angle as indicated by doing Vector3.Angle(a-b, Vector3.forward).

Without more information on exactly what angle you are trying to get (and in reference to what), I can't tell you exactly what you will need to pass in to Vector3.Angle. But regardless, it will need to be directions, not positions.


vector3angle.png (2.6 kB)
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 Figgo · May 18, 2017 at 07:51 AM 0
Share

Thank you, that really clears things up. It works like I wanted it to now, and I'll have to toy with some settings but it's really getting there now.

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

123 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

Related Questions

How to prevent the player to move beyond certain x-position value 3 Answers

Saving old Position 1 Answer

Transport only Z position 1 Answer

How to put an object in front of the player when clicked 0 Answers

Move Character in the way he is facing.,Make character move in way he is facing. 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