Download

Vector Math help

Hey guys, i was hoping you could help me out with converting some python/C# code,

Im trying top achieve rotating the module block,
animation-modulematching-600px.gif

I understand the principles, but not the syntax or the math. I need to make a Rotate around command, as there is none in Unreal i can see.
My understanding of math is pretty simple, but im willing to give this a go.

C# Code


	private void MatchExits(ModuleConnector oldExit, ModuleConnector newExit)
	{
		var newModule = newExit.transform.parent;
		var forwardVectorToMatch = -oldExit.transform.forward;
		var correctiveRotation = Azimuth(forwardVectorToMatch) - Azimuth(newExit.transform.forward);
		newModule.RotateAround(newExit.transform.position, Vector3.up, correctiveRotation); //Rotate Around? I can not find a similar function in Unreal. 
		var correctiveTranslation = oldExit.transform.position - newExit.transform.position;
		newModule.transform.position += correctiveTranslation;
	}

	private static float Azimuth(Vector3 vector)
	{
		return Vector3.Angle(Vector3.forward, vector) * Mathf.Sign(vector.x); //X because x is left right in unity and this code is taken from Unity source code. 
	}

Id love some help! does anyone know of a command to make a object rotate around a given vector (like a pivot point) similar to this https://docs.unity3d.com/Documentation/ScriptReference/Transform.RotateAround.html ?

And how can i handle Azimuth in Unreal engine? Is there an equal command to find a global forward vector?
Anyway, thank you very much! im pretty new to all this.

A “rotate around point” is three steps:

translate by -vector
rotate
translate by +vector

For the facing/right/up vector you can use:

GetActorDirectionHereVector();

If you want an object to simply rotate however, you should be able to set the rotation each frame perhaps:


SetActorRotation->(GetActorRotation().Pitch + someVal, GetActorRotation().Roll + someVal, GetActorRotation().Yaw + someVal);

Toxic fork, can you explain this with alittle bit more detail?
where vector one = A, Vector 2 (the point) = b
A.location * -B.location
A.rotate(whatever)
A.location * B.Location,
is that right? is that how you mean

Dune, thanks for your answer but im trying to achieve this :

Adding a ‘rotate around’ function sounds like a good idea, I’ll add that to the list!

Sounds good JamesG, Your the man.
Might pause development of the random generation side of my game till then. :slight_smile:

Oh, it looks like you want to have a vector as the axis of the rotation… that one’s different. Not really sure how to achieve that in ue.