- Home /

# 2D angle of two Vec3

How can I calculate 2D angle of two Vec3?

I am trying to find angle between wing forward vector and velocity vector. I found on forum nice code for angle between two vectors. My problem is when my object turns left or right the velocity vector does not turns with object. Of course it`s normal. I need to find plane (XY) angle or make new vector based on velocity vector and turning with plane. Because

this falsifies my angle.

Thank you.

The trick is to think of *which* 2D plane to measure over, which is usually called a projection. The second picture, it measures over the "real" 2D plane glued to the front of that wing (which is easy, and doesn't even use projection. Just `Vector3.angle`

)

The first picture, it looks maybe like the 2D plane is going straight down from the from of the fuselage (but not sure, it has to do with lift?) In that case, you project each vector onto that plane, and then measure.

But it starts with figuring out exactly which plane (does yours tilt when the plane rolls?)

From what i understand you should project velocity to the plane defined by airplane.up and airplane.forward vectors, and take the angle between that vector and airplane.forward.

@NoseKills seems right to me; in fact, for computing lift, you probably just need the dot product of the velocity and airplane.up (or wing.up if it's appreciably different).

I like the other comments, but let me try to explain a different way. The airstream vector you are looking for can be described as “the component of the velocity vector that is pointing forward”. Much like you would say the Y of the velocity vector can be described as “the component of the velocity vector that is pointing up.”
Obviously you won’t be able to just extract a single coordinate here, instead you will want to use a dot product of your velocity vector and your forward vector. This will tell you how fast you are moving in the forward direction. The dot product computation INCLUDES the angle you are looking for and is defined as |VectorSpeed| Cos(theta), where theta is the angle between the two vectors. Multiple this scalar (a non-vector) result with your VectorForward to get the final vector your looking for. You can also use this formula and the dot product result to determine the angle theta.

This picture in the wiki for dot product has a great picture that describes this exactly.

http://en.wikipedia.org/wiki/Dot_product#mediaviewer/File:Dot_Product.svg

Thank you all. Should be some '+' or 'Thanks' button in comments.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

How to find direction Vector for a collision surface? 1 Answer

Calculate launch angle based on launch direction 2 Answers

Orienting multiple objects on the same line 1 Answer

Finding rotation 0 Answers