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

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.

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. :wink:

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

1 Like

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

	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. :smiley:

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

1 Like

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 :vulcan_salute:

  • the undesired gimbal locked Find Look At Rotation behaviour:

  • unlocked:


Play with those:

To get whatever carousel you might need going.

1 Like

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

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

At least you put me 1 step forward :pray:

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

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.

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