This site uses strictly necessary cookies. More Information

X- Home /

# Calculate point coords which lays on normal vector

Hello. I have A and B points which z coord the same. I need calculate point C coords between this two points and calculate D point coords, which lays on normal vector to AB vector, and on length l.

I can calculate C point coords using A.transform.position + (B.transform.position - A.transform.position) / 2f but how can I do other stuff (calculate D point coords)? (this is 2d game and z coords always 0 for all points) thanks.

**Answer** by Prodigga
·
May 16, 2013 at 02:03 AM

If you get a cross between (B-A) and whatever is the 'up' vector for your points (the vector pointing to you from your screen), then this will give you a vector (which we will call 'N') that points perpendicular to the line A->B. If you normalize 'N', then

`D = C + N * distance to D`

Thanks. But can you explain a little bit more about how can I get N vector which will be perpendicular to AB using only world forward direction and A and B coords? Thanks again!

**Answer** by robertbu
·
May 16, 2013 at 03:23 AM

As @Prodigga indicates, the cross product is a good way to go to solve this problem. Given you have positions A and position C (which you calculate in your question) here is a bit of code:

```
var v3AC = v3A - v3C;
var v3D = v3C + (Vector3.Cross(v3AC, Vector3.forward)).normalized;
```

You can change which side of the line the point is on by either changing the order of the parameters in the Vector3.Cross() or by using Vector3.back instead of Vector3.forward.

### 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

Find a point between 2 vectors for a specific Y 1 Answer

2D Array for pathfinding 0 Answers

Obtaining a perpendicular point? 1 Answer