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 /
This question was closed Feb 02, 2017 at 06:55 PM by MohsenneChaverdie for the following reason:

Too subjective and argumentative

avatar image
0
Question by MohsenneChaverdie · Jan 31, 2017 at 02:46 PM · rigidbody2dvelocityanglevector2

Why angle between these two velocities is 45?

Degree between Vector2(rigidBody2d.velocity.x, rigidBody2d.velocity.y) vs. Vector2(rigidBody2d.velocity.y, rigidBody2d.velocity.x) is 45. Why? How can I have 90?

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

2 Replies

  • Sort: 
avatar image
1

Answer by MelvMay · Jan 31, 2017 at 03:22 PM

Given a Vector of (x,y), to find a perpendicular vector you use:

  • Vector (y, -x) for clockwise

  • Vector (-y, x) for anti-clockwise

You can get the angle of a 2D vector using: Mathf.Atan2 (y, x). This will give you the angle in radians of that vector. You can get therefore get the angle between two vectors using Mathf.Atan2 (y1, x1) - Mathf.Atan2 (y2, x2).

Comment
Add comment · Show 4 · 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 MohsenneChaverdie · Jan 31, 2017 at 03:36 PM 0
Share

I know that I need to swap the x and y to have perpendicular vector2, but when it comes to rigidBody2d.velocity, it is not working. The movement will be in 45 degree, not 90!

avatar image NoseKills MohsenneChaverdie · Jan 31, 2017 at 04:04 PM 0
Share

The example code you posted doesn't negate x or y. It turns e.g. a velocity of (1,1) into a velocity of (1,1) -> angle 0.

Your code does not do what the answer tells you to do. Please fix the code in your question or try the fix in the answer, which ever is the case.

avatar image MohsenneChaverdie NoseKills · Jan 31, 2017 at 04:08 PM 0
Share

var angleBetweenTwoVelocities = Vector3.Angle(rigidBody2D.velocity, new Vector2(rigidBody2D.velocity.y, -movementSpeed)); Debug.Log(angleBetweenTwoVelocities);

// console will show 45

Show more comments
avatar image
0

Answer by MohsenneChaverdie · Jan 31, 2017 at 10:19 PM

I am so sorry for wasting your time. I really did not mean to do that. I should not have asked that question. Sorry again.

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

Follow this Question

Answers Answers and Comments

91 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

Related Questions

Rotating a velocity vector while keeping the magnitude 0 Answers

JohnyControllerScript.cs(20,17): error CS0029: Cannot implicitly convert type `UnityEngine.Vector2' to `UnityEngine.Rigidbody2D' 0 Answers

How to stop cube from sliding (rg2d.velocity) 1 Answer

Calculate velocity x and y directions based on speed and angle 0 Answers

why is the rigidbody's velocity zero in OnCollisionEnter2D? 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