CFrame is being inaccurate

I want to make this knife model face directly forward while I use telekinesis on it, but it keeps pointing down…


If its facing how I want it to when the orientation is 45,0,0 why is it facing down when i set it to 45,0,0 in the script??
image

			local BG = Instance.new("BodyGyro", Object)
			BG.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			BG.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(45,0,0)
			BG.Name = "TKGyro"

			while player and BP and TK[Object] do
				wait()
				BP.Position = (player.Character.RightHand.CFrame * CFrame.new(1, -1.25, 0)).Position
				BG.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(45,0,0)
			end
		end

2 Likes

try math.rad(45) instead of 45

2 Likes

it’s still pointing down
image

2 Likes

math.rad(45) means exactly that position, 45 degrees downward front, have you tried just removing the * CFrame.new() altogether? and what position does it partake when you do

1 Like

... * CFrame.Angles(math.rad(45), 0, 0) and debug from there. You should also use AlignOrientation becuase BodyGyro is deprecated.

2 Likes

i tried reading through alignorientation documentation and its just confusing me more each time i read it

1 Like

when i remove it it just does the exact same thing
image

2 Likes

I setup a dummy tool with a handle that had the visual part (blade) rotated by -45 deg on the X axis (to simulate the rotational offset).

I was able to run something close to this and got this working in one try:

local OFFSET = CFrame.new(1, -1.25, 0)
local ROT = CFrame.Angles(math.rad(45), 0, 0)

while true do
	task.wait()
	BP.Position = (rightHand.CFrame * OFFSET).Position
	BG.CFrame = (root.CFrame * ROT)
end

So, you’re using cf * CFrame.new, which does relative positional offset (not changing rotation - so no impact), instead of cf * CFrame.Angles which you need to supply radians to.

3 Likes

If you’re unable to get this to work, your BP and BG properties need fine tuning, also the effect itself isn’t great since movement of the hand will cause the blade to not really be stable.

1 Like

First of all, BodyGyro is deprecated, deprecated stuff are deprecated because there’s a more efficient way of doing it or because it was buggy and inaccurate. You should be using AlignOrientation. And as the name suggest, AlignOrientation aligns orientation.

Secondly, how do you use AlignOrientation?
Well it there’s a lot of factors on how it can be used, though I’ll only be focusing on the mode and MaxTorque, the things you should also only care about when looking at your post.

When you make an AlignOrientation it defaults to “TwoAttachment”
TwoAttachment mode is when you use 2 attachments (wow who knew), and if you rotate attachment 1, attachment 0 will follow.

OneAttachment mode (The one you should use), as the name suggest, uses one attachment. Using OneAttachment mode will open up a new CFrame property in the AlignOrientation(scroll down to find it). It’ll also make Attachment0’s orientation follow whatever orientation you set the AlignOrientation’s orientation as.

MaxTorque affects how much, I guess, power should be used in rotating Attachment0, the higher it is, the easier it is for it to rotate the attachment, in this case, you should just set it as a high number like 999999, set it higher, if, for some reason the knife doesn’t rotate.

2 Likes

it worked perfectly, thank you so much! :heart:

thank you, i will look into alignorientation for future scripts

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