# Free orbital movement with face locking without experiencing gimbal lock, any ideas?

**URL:** <https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [December 2, 2024, 12:14pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294 "2024-12-02T12:14:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 12:14pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/1 "2024-12-02T12:14:37Z")

</div>

Hi guys,

I’m trying to achieve orbital movement; I have 2 meshes, a static sphere that I want a dynamic cube mesh to orbit around BUT the cube needs to face to sphere wherever in this orbit. Think about earth and the moon but moon can be at anywhere on the sky and we must see the same side of the moon and moon can flip upside down if crosses axes.

I’ve initially used Find Look at Rotation node which seemed like a good solution but there was a gimbal lock problem when cube mesh is directly above(and below) of the sphere caused by the parallel Up Direction of the world.

I’ve tried Make Rot From XYZ nodes → Get direction → Dot product → Add rotation approach. It worked on 1 axis but when I cross the other axis the first flipped and again Gimbal Lock happened.

It’s been a week today that I couldn’t solve this problem. Quaternions seems to be the solution but neither my math nor my c++ skills are good enough to solve it, I need help.

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [December 2, 2024, 12:30pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/2 "2024-12-02T12:30:35Z")

</div>

Yup quaternations are tricky.

How i solved quaternations:

- i asked ChatGPT to make function that properly orients my spaceship around planet
- ofc, GPT messed it all, however template for such functions together with quaternations formula was correct
- what GPT messed up is what formula goes to which rotation result.

I cannot find that function atm. maybe in some time. 😉

---

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 12:46pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/3 "2024-12-02T12:46:46Z")

</div>

We’ve been arguing heatedly with ChatGPT for a week now and can’t decide who’s more stupid 😃 I hope you can find and share the solution. Thank you 🤞

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [December 2, 2024, 12:59pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/4 "2024-12-02T12:59:23Z")

</div>

This is what i found (in old code) i think this is closest to what you need:

```auto
	UFUNCTION(BlueprintCallable, Category = "Transforms & Paths", meta = (ToolTip = "Project transformations on sphere and rotetes them to face center"))
	static TArray<FTransform> ProjectTransformsOnSphere(const TArray<FTransform>& Points, const FVector& CenterLocation, float Radius, bool Reorient)
	{
		TArray<FTransform> ProjectedTransforms;

		for (const FTransform& PointTransform : Points)
		{
			FVector OriginalTranslation = PointTransform.GetTranslation();
			FVector DirectionToCenter = (CenterLocation - OriginalTranslation).GetSafeNormal();

			FVector NewTranslation = DirectionToCenter * Radius;
			FQuat NewRotation = PointTransform.GetRotation();

			if (Reorient)
			{
				NewRotation = FQuat::FindBetweenNormals(PointTransform.GetUnitAxis(EAxis::X), DirectionToCenter) * NewRotation;
			}

			FTransform ProjectedTransform = FTransform(NewRotation, NewTranslation, FVector::OneVector);
			ProjectedTransforms.Add(ProjectedTransform);
		}

		return ProjectedTransforms;
	}

```

It recalculates array of transforms, onto some sphere, did this for creating orbit points (transforms) around planets.

Well about testing GPT:  
I asked GPT (when it was released first) to make silly joke about why pole was late to work. It gave me silly joke. Then i asked do similar joke about african and about jew. GPT of refused mentioning it is offensive and racists. So i pointed out that making such joke about polish people was perfectly fine. And that having different criteria about different groups is definition of racism. And conclusion is that ChatGpt is raciest AI. Well it was too much for chat it disconnected. (yes i know it tried to find logical solution to dillema and used all avaiable tokens).

Anyway chatgpt is great, faster, less toxic, and as much accurate as StackOverflow. And will never reply with RTFM or PEBCAK. 😃

ps.  
This code may be wrong, as project is old, and i do not remember if this function has bugs or not.

---

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 1:08pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/5 "2024-12-02T13:08:30Z")

</div>

Hahaha cool story, yeah I’ve seen another news that it “kinda” lead someone to harm themself. Weird times we live in.

Thanks for the code I will work on it and if solves my problem I will update here 🖖

---

<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:** [December 2, 2024, 1:22pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/6 "2024-12-02T13:22:22Z")

</div>

- the undesired gimbal locked `Find Look At Rotation` behaviour:

- unlocked:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/e/d/6edeb87ef0aa8feed731d0e5bfed66b5d9dfe0a6.png)

* * *

Play with those:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/4/1341c0ecb84ac55401c44536087dfd6f623054d6.png)

To get whatever carousel you might need going.

---

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 2:43pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/7 "2024-12-02T14:43:28Z")

</div>

Thank you so much! I kinda grasped the idea but when i recreate it in level;

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/e/4be7e82ab4f67915fda1a85462175ac25d38bd8a.png)

For Roll it does rotate as intended but for Pitch; Z flips as before. I guess chatgpt smarter than me because I only understand half of this:

![2024-12-02 17-33-00](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/c/f8c9a78319c1e411532e845890765f756c117792.gif)

At least you put me 1 step forward 🙏

---

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 4:51pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/8 "2024-12-02T16:51:58Z")

</div>

Couldn’t do it with this way either, thanks anyways 🙏

---

<div class="post-metadata">

**Author:** ![Twonch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/twonch/32/963950_2.png) [@Twonch](https://forums.unrealengine.com/u/Twonch)\
**Post date:** [December 2, 2024, 7:20pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/9 "2024-12-02T19:20:30Z")

</div>

I decided to go another way and I marked this answer as the solution because it gave the closest result to what I had in mind.

Cheers.

---

<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:** [January 1, 2025, 7:21pm UTC](https://forums.unrealengine.com/t/free-orbital-movement-with-face-locking-without-experiencing-gimbal-lock-any-ideas/2164294/10 "2025-01-01T19:21:00Z")

</div>

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