How would I convert a direction vector to a 3D rotation vector?

I have a direction vector calculated by getting the vector from PointA to PointB .Unit. How would I convert this vector into a 3D rotation vector (36,210,-43) for use in a BodyGyro, so a part could face this point using the physics engine?

1 Like

BodyGyro has a CFrame property which’ll only change to the rotational data in the CFrame.

You could construct a CFrame using the overload: : Vector3, LookAt : Vector3)

Then set the BodyGyro’s CFrame to this newly constructed CFrame.

1 Like

This doesn’t seem to work however. I get jerky movements that don’t coincide at all with the direction I want it to face. That method is also deprecated.

If you want the BodyGyro to make a part or assembly face a certain position, that should work. No direction vector is needed at all.

I explained however, that it doesn’t work. Constructing a CFrame (using the deprecated method) results in incredibly jerky movements with my BodyGyro.

Hmm, perhaps it may be best to use CFrame.FromMatrix for this then, it takes a rightVector and upVector to create a rotation.

Cross the directional you have with a Vector with just 1 in the Y axis to get the rightVector then you can Cross the rightVector with the directional to get a upVector.

Code example:

local Position = --// Position here
local Direction = --// Vector here
local Up = Vector3.FromAxis(Enum.Axis.Y)
local RightVector = Direction:Cross(Up)
local UpVector = RightVector:Cross(Direction)

local CoordinateFrame = CFrame.FromMatrix(Position, RightVector, UpVector)

Seems to work fine for me.

Maybe your BodyGyro settings are not correct.

1 Like