How to get the relative orientation between 2 cframes

When a player grabs an object, theoretically it should lock the parts cframe orientation to the cameras cframe, I store this as a variable and change the bodypositions value in a renderstepped loop

As of now, the calculations i’ve put in place are entirely wrong (utilized cframe:ToObjectSpace and ToEulerAnglesXYZ), it spins the object and grabs the orientation incorrectly


heres a short video demonstrating my grabbing system as of now

the calculation used in the video was

module.RelativeOrientation = CFrame.fromEulerAnglesXYZ(camera.CFrame:ToObjectSpace(object.CFrame):ToEulerAnglesXYZ)

for the renderstepped loop

module.OrientGyro.CFrame = camera.CFrame * module.RelativeOrientation

Any help is appreciated.

BodyGyro ignores the position of its CFrame property, so have you tried not reconstructing a CFrame like you did for module.RelativeOrientation?

It might not do much, but try doing that and see if it changes anything.

module.RelativeOrientation = camera.CFrame:ToObjectSpace(object.CFrame)
1 Like

change this line of code to make the getting of the relative orientation more accurate and efficient

module.RelativeOrientation = camera.CFrame.Rotation:ToObjectSpace(object.CFrame.Rotation)

also i suppose that the parrent of BodyGyro is that small white ball right? if that is so, make sure the CFrame orientation of that ball is equivalent to the orientation of your object before welding it. what is happening here, i assume, is that your ball is being positioned and welded on the surface of the object without any inital rotation which causes this ball to rotate in unwated orientations when BodyGyro is applied

1 Like

ive already tried this, sorry for not specifying
i spent at least an hour going through a ton of calculations

Should’ve said this when i made the post, but when the player is not grabbing, the alignposition and alignorientation is parented to the camera, when the player is grabbing an item, they are both parented to the item, plus the attachment that is visible via the white ball. both alignposition and alignorientation are using this attachment.

for specifics regarding the alignposition, it doesnt apply to centre of mass, doesnt use rigidityenabled

It seems in this situation, objectspace and worldspace doesnt work here. which for me, makes no sense.

oh well, i thought you were using BodyGyro not BodyOrientation, nonetheless the problem stays the same as i described above but instead of making sure the part’s orientation is the same as the object’s you have to rotate the attachment

example:
Attachment.CFrame = ItsPositionOnTheSurface + Object.CFrame.Rotation

1 Like
local relative_cframe = cframe1:ToObjectSpace(cframe2)
local x, y, z = relative_cframe:ToOrientation()

local orientation = Vector3.new(x, y, z)
1 Like

Cheers for reminding me that it was the attachment.
Appreciate all of you for trying.

1 Like

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