# Forward Vector from normal flipping SOLVED! (sorry don't know how to mark it as such officially)

**URL:** <https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832>\
**Category:** Blueprint\
**Tags:** unreal-engine, Physics, Blueprint, vector-math\
**Created:** [February 19, 2023, 3:55am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832 "2023-02-19T03:55:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertoCosta\_Dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RobertoCosta\_Dev](https://forums.unrealengine.com/u/RobertoCosta_Dev)\
**Post date:** [February 19, 2023, 3:55am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/1 "2023-02-19T03:55:11Z")

</div>

SOLVED! (sorry don’t know how to mark it as such officially)  
Long story short, omni-directional gravity and the requirement to rotate in line with that. Issue is when the sign of an element of a normal (used to calculate axes) is switched, it reverses the direction of the forward or right vectors (depending on the normal).

Example  
Normal Vector is x = 0, y = 1, z = 0  
Everything is fine.  
Normal Vector is x = 0, y = -1, z = 0  
Forward vector is flipped

I’m currently calculating the vectors as so  
Up vector = normal  
Forward Vector = cross product of normal with Up Vector  
Right Vector = cross product of Forward Vector with Up Vector

I’ve solved this problem is the past but at the time I had a very specific use case that gave me an obvious workaround (I could modify the direction by taking into account velocity). This time round however I’m stumped.

Visual Aid:  
Vector output performing correctly.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/a/5/2a5029352f64beeef00518d9ecadf80524cd21dd.jpeg)  
Vector output reversed  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/4/e642cc54dc8b0549f60a4b092000e05ff6ad8d5f.jpeg)

I feel like the answer to this is staring my right in the face and not finding it is maddening.

Here is the code in case text wasn’t clear.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/d/d2de8242545a9fd04a3223c62709a56c454b20fe.png)

---

<div class="post-metadata">

**Author:** ![ShawnDaGeek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shawndageek/32/734104_2.png) [@ShawnDaGeek](https://forums.unrealengine.com/u/ShawnDaGeek)\
**Post date:** [February 19, 2023, 4:36am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/2 "2023-02-19T04:36:19Z")

</div>

_About Normalizing: If magnitude is 0 the gods of maths cry._

I cheat when i have to vector flip, by adding a teeny tiny amount of velocity just before i normalize, “use case”.

Have you tried breaking vector before Normalize and flipping forward V there, make new V for Normalization?

> [@ShawnDaGeek](#):
>
> _About Normalizing: If magnitude is 0 the gods of maths cry._
> 
> I cheat when i have to vector flip, by adding a teeny tiny amount of velocity just before i normalize, “use case”.
> 
> Have you tried breaking vector before Normalize and flipping forward V there, make new V for Normalization?

> **[Normalize](https://docs.unrealengine.com/5.1/en-US/BlueprintAPI/Math/Vector/Normalize/)**
>
> Normalize

---

<div class="post-metadata">

**Author:** ![RobertoCosta\_Dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RobertoCosta\_Dev](https://forums.unrealengine.com/u/RobertoCosta_Dev)\
**Post date:** [February 19, 2023, 5:08am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/3 "2023-02-19T05:08:00Z")

</div>

Hi, thanks for the reply, fortunately this is not a problem. The normal of a surface can never be 0 (afaik) unless the hit result comes back false. I do take into account if it is 0 already to calculate whether I should set the gravity vector or keep the old one.

I’ve managed to narrow down the issue since I posted. But unfortunately it’s also led me to the realization that this behavior is actually something I’d want in many cases. traversing a loop. The issue arises at poles and when standing on surfaces that would flip the vector. So Honestly I’m in even more of a bind than when I started.

---

<div class="post-metadata">

**Author:** ![ShawnDaGeek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shawndageek/32/734104_2.png) [@ShawnDaGeek](https://forums.unrealengine.com/u/ShawnDaGeek)\
**Post date:** [February 19, 2023, 5:11am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/4 "2023-02-19T05:11:29Z")

</div>

> [@RobertoCosta\_Dev](#):
>
> The issue arises at poles and when standing on surfaces that would flip the vector.

I had a similar issue with gimbal locks on an older project, pole = 0.  
If approaching a pole or at a pole you can make a slight adjustment to that 0 as so you are never dividing/multiplying by 0.

---

<div class="post-metadata">

**Author:** ![RobertoCosta\_Dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RobertoCosta\_Dev](https://forums.unrealengine.com/u/RobertoCosta_Dev)\
**Post date:** [February 19, 2023, 5:22am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/5 "2023-02-19T05:22:07Z")

</div>

I think either you’re talking about something I don’t understand or we’re not on the same page haha

Either way I’ve found a temporary fix with some trade offs. I had to dip into the dreaded realm of quarternions but it works. Answer was about as simple as I feared. If y \< 0, rotate the rotator by 180 degrees along its relative yaw axis.

While you may have not directly given me the answer here I have to thank you for tickling my brain enough to make me attempt something weird at the ungodly hour of 05h30 haha.

---

<div class="post-metadata">

**Author:** ![ShawnDaGeek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shawndageek/32/734104_2.png) [@ShawnDaGeek](https://forums.unrealengine.com/u/ShawnDaGeek)\
**Post date:** [February 19, 2023, 5:28am UTC](https://forums.unrealengine.com/t/forward-vector-from-normal-flipping-solved-sorry-dont-know-how-to-mark-it-as-such-officially/773832/6 "2023-02-19T05:28:51Z")

</div>

if y = 0 then y = y + .0001 based on the tolerance you set in your normal. Before the normal though, as it will not normalize if it is not safe to do so.

_Gets a normalized unit copy of the vector, ensuring it is safe to do so based on the length. Returns zero vector if vector length is too small to safely normalize._

> **[Normalize](https://docs.unrealengine.com/5.1/en-US/BlueprintAPI/Math/Vector/Normalize/)**
>
> Normalize
