# Projecting Vector using dot product help

**URL:** <https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [May 28, 2024, 1:53pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047 "2024-05-28T13:53:02Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 28, 2024, 1:53pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/1 "2024-05-28T13:53:03Z")

</div>

Hi there,  
So my brain is completely fried and I seemed to have forgotton basic vector math.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/4/4/444ee0c7fde2f9592c8c1e830f7ecd15c281a32f.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/9/6090d18e6334d82f5e5b6538c1e8ee00b47c5935.jpeg)  
red is unreals trace.  
yellow is my indication how far it should go.  
Green is the target “line” the rays should extend to.

What I am trying to accomplish is basically my line trace projecting back to the orthogonal of the vector between the player and the object. It should shoot rays as far as the green plane. I am using the dot product and I am not sure where I am going wrong. If anyone has a solution it would be greatly appreciated! 🙂

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 28, 2024, 3:00pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/2 "2024-05-28T15:00:43Z")

</div>

I would try putting everything on the click event for starters. At the moment, there’s no guarantee what you’re getting from tick is synchronized with the other stuff.

---

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 28, 2024, 3:02pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/3 "2024-05-28T15:02:53Z")

</div>

tick is only a debug arrow i am drawing temporarily. The actual math happens without any tick.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 28, 2024, 3:05pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/4 "2024-05-28T15:05:25Z")

</div>

You’re right, sorry 🙂

---

<div class="post-metadata">

**Author:** ![ullmatta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ullmatta/32/491477_2.png) [@ullmatta](https://forums.unrealengine.com/u/ullmatta)\
**Post date:** [May 28, 2024, 3:08pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/5 "2024-05-28T15:08:45Z")

</div>

Hey, I don’t get what you’re trying to do, but you could use a “line plane intersection” node, if you want to do what I think you do.

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [May 28, 2024, 3:53pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/6 "2024-05-28T15:53:19Z")

</div>

I’m not familiar with line plane intersection so I’m not sure if that’s what you want, but here’s how to do it using trig

Effectively all we do is divide distance by cos(theta), theta being the angle delta between the axis and player rotations. For Y we have to subtract 90.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/9/e69cc0fbdbf4b212772fe0df735040a1fe9216a8.jpeg)

Resulst:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/2/f02e5cb4ade0a2cd0045a050dc96bd94cf2bc6d7.jpeg)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/7/3/f73efc449c9c37fd979ee17b047015e22bee86b5.jpeg)

---

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 28, 2024, 4:43pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/7 "2024-05-28T16:43:36Z")

</div>

To clarify, here is what I am trying to do.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/5/9/159dedc0ab49a2756717e45117529c4f941c64c0.png)

I want to shoot rays from cam and it should go into the direction until its perfectly orthogonal between the red vector and not past that.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/1/781885b21277772037d1da46c66489791c9a66a5.png)

like so. However may rays seem to be too short. I notice that the rays I fire are orthogonal to the target however what I want to ensure is that the rays going from p to fired ray and ray to cam are orthogonal, not the fired ray to the point p

currently, I get these results:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/0/740a6232d978a6c49ddaa055cedf43b4789a05a9.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 28, 2024, 4:54pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/8 "2024-05-28T16:54:33Z")

</div>

It has so many applications that, once you know how it works, there’s no looking back. Some examples:

> [@Left Mouse button pressed and released equivalent in enhanced input (or drag and drop)](https://forums.unrealengine.com/t/left-mouse-button-pressed-and-released-equivalent-in-enhanced-input-or-drag-and-drop/1633884/18):
>
> Here’s some script allowing for picking up stuff and moving it in a specific plane only we determine ourselves manually: The green debug plane visualises what’s going on. In short: shoot a beam (trace) from the screen centre towards the projected mouse cursor, when it eventually intersects that plane (which is infinitely large), place the actor at the intersect world coordinate. If I change the normal: You could derive this Normal from the actor itself instead:

> [@Line Trace from a 3d point to mouse location](https://forums.unrealengine.com/t/line-trace-from-a-3d-point-to-mouse-location/237661/3):
>
> You’re tracing with a fixed distance of 500, replacing the projection’s X with a fixed value. It’s actually hard to imagine how that would look like, a strangely distorted / twisted undulating surface mayhaps? cool, for sure. I want this trace to stay on the same plane as my character, so the X value of the start point & end point should be the same. Consider the following: green_circle create a virtual plane where the character is and point it towards X (Plane Normal 1,0,0) …

---

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 28, 2024, 4:57pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/9 "2024-05-28T16:57:50Z")

</div>

this looks like something that would solve this, ill check it out and let you know 🙂

---

<div class="post-metadata">

**Author:** ![ullmatta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ullmatta/32/491477_2.png) [@ullmatta](https://forums.unrealengine.com/u/ullmatta)\
**Post date:** [May 28, 2024, 7:07pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/10 "2024-05-28T19:07:20Z")

</div>

These functions are built in allready.

 ![Screenshot_2024-05-28 21.12.40](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/9/58925990d190d6b1428d5478786ee4aa33206187.jpeg)  
 ![Screenshot_2024-05-28 21.13.03](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/2/6825c93bc07bf4eed32f610e25049c8083442dd6.jpeg)  
 ![Screenshot_2024-05-28 21.14.54](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/f/6ff22c69202d144fccc7ffd361d5203af6534e28.jpeg)  
(edit added blue lines)

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 28, 2024, 7:31pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/11 "2024-05-28T19:31:31Z")

</div>

here is another one.

  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/4/4/644ab76e471f48e37ec640a1e1da0cce30f7f7d6.jpeg)

---

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 29, 2024, 4:24pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/12 "2024-05-29T16:24:04Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/1/8a1b6ecba3f315336d62c0a8e84dbf6a1cc77fdd.jpeg)  
can you explainthis bit?

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 29, 2024, 6:05pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/13 "2024-05-29T18:05:00Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/b/93bd3d1b2970452cf0f56c47885f1983a68d6112.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/5/6/256b4ef2ce0c8bc3a9926778723324e154c45aee.jpeg)  
dot product + acosd is a fixed formula for getting the angle degrees to me ,I don’t know why it can do that though.I just know how to use it.

---

<div class="post-metadata">

**Author:** ![MadPolygon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/madpolygon/32/268902_2.png) [@MadPolygon](https://forums.unrealengine.com/u/MadPolygon)\
**Post date:** [May 29, 2024, 7:10pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/14 "2024-05-29T19:10:30Z")

</div>

this makes sense and is actually pretty simple, not why my intuition didnt grab that! Thank you!

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [May 29, 2024, 7:26pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/15 "2024-05-29T19:26:40Z")

</div>

The dot product of two unit vectors is the cosine of the angle. It doesn’t need to be turned into an angle then cos() again.

To get the length we can just do `adjacent / dot product = hypothenuse.`

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 29, 2024, 7:33pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/16 "2024-05-29T19:33:37Z")

</div>

> [@pezzott1](#):
>
> The dot product of two unit vectors is the cosine of the angle.

I didn’t know this before,well now I know 😂 .thanks

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [June 28, 2024, 7:33pm UTC](https://forums.unrealengine.com/t/projecting-vector-using-dot-product-help/1877047/17 "2024-06-28T19:33:47Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
