Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 windexglow · Jul 23, 2010 at 04:34 PM · rotationvector3angledegrees

0-360 Y degree from Vector3.Angle

Having trouble with my pixel-movement code, which I'm pretty sure is having problems with Vector3.Angle Made in java, kind of stumped.

//loc = Vector2, this moves towards the endpoint. //endpoint = Vector2, this is stationary.

var dir_difference : float = Vector3.Angle(Vector3(loc.x, loc.y), Vector3(endpoint.x, endpoint.y));

I want dir_difference at this point to be 0-360, but it's instead returning 6-9, passing the endpoint without changing very much.

The rest of my code should work well enough, since it's splitting it down to a 0-7 int which I use to move the pixel.

//dir = last direction the pixel moved in. 0-7
dir_difference = Mathf.Repeat  (Mathf.Round(dir_difference / 45 ) , 8); //should return 0-7
dir_2 = dir_difference;
dir_difference = Mathf.Abs(dir - dir_difference); //total difference between angles.  Tells me if it needs to move left or right, and how soon

EDIT: To clarify, I'm looking for something that would return something akin to

225 270 315
180 xxx 000
135 090 045

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 Bampf · Jul 23, 2010 at 05:29 PM

The arguments to Vector3.Angle are themselves directions; you seem to be passing in positions.

Try subtracting the two positions to get the vector: vec = endpoint - loc

The length of this vector is the distance between the two points; the "slope" of the vector is the direction to travel. You can then convert this into an angle using the Vector3.Angle method. But, you need a starting angle. For example, you might choose the X-axis as your starting angle:

var angle : float = Vector3.Angle(Vector3.right, vec);

You can then use this angle to assign an integer (0-7) to the direction as you had planned to originally. (Although, that code may also need tweaking. What's dir_2 for? Is dir the last calculated direction?)

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 windexglow · Jul 24, 2010 at 09:26 PM 0
Share

I don't quite understand where to go with that - - my math is embarrassingly rusty.
225 270 315 180 xxx 000 135 090 045

avatar image Bampf · Jul 28, 2010 at 10:49 AM 0
Share

You originally asked for integers 0-7 but in your new comment it looks like you are rounding to the nearest 45 degree angle? Also, it's not clear whether you wanted 2 or 3 dimensions- you omit the z argument a few times. Can you clarify? $$anonymous$$aybe explain what you'll be doing with these numbers. Is this for movement around a grid?

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

No one has followed this question yet.

Related Questions

Place object on radius pointing to a other object 1 Answer

Trying to get the angle of a camera object based on players forward, is not distance independent 0 Answers

Unity 8-Directional Locked Movement (Super Mario 3D World Style) 3 Answers

How do I find the angle between the players forward vector and the mouse position? 1 Answer

Quick Angles Question 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