Too subjective and argumentative
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?
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).
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!
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.
var angleBetweenTwoVelocities = Vector3.Angle(rigidBody2D.velocity, new Vector2(rigidBody2D.velocity.y, -movementSpeed)); Debug.Log(angleBetweenTwoVelocities);
// console will show 45
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.