Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cframe resets rotation. How do i fix?

When im using Cframe it resets the rotation to 0

This is the script im using

shaft = script.Parent.Shaft
ball = script.Parent.Ball
for i = 1,309 do
	shaft.CFrame = CFrame.new(shaft.Position + Vector3.new(0,0.1,0))
	ball.CFrame = CFrame.new(ball.Position + Vector3.new(0,0.1,0))
	wait(0.1)
end

2 answers

This is kind of complicated, but let me try to explain.

CFrame usually looks like this: CFrame.new(Position, Orientation). But, it's kinda stupid. The second part, orientation, is also a position, meaning the part will face towards whatever position you put into the Orientation. For example, if I made a script saying Block.CFrame = CFrame.new(Block.Position, Ball.Position), the Block will face towards the ball. Pretty simple, right?

So, here's the issue: Your script leaves the second part of the CFrame empty, which means that by default, it resets the orientation. There are three ways to fix it, the last being the most efficient:

  1. Set the Orientation Back every time you change the CFrame
  1. Find the position in front of where your block was facing, and set that as the second part of the CFrame.
  1. Use Position Instead of CFrame.

Like I said, it's pretty stupid, but it's useful if you want to make something like an NPC that faces towards your character, or a gun that fires where your mouse is aimed. It's best that you just use Position Instead of CFrame when making your type of script. Changing the position doesn't change the orientation, unlike CFrame.

5 comments

0

This is helpful. I think my drag tool, unlike other drag tools resets the orientation because it uses CFrame changes instead of position changes. This is a very interesting question/answer.

0

Thanks. I edited my answer like 5 times just a moment ago, so you might want to reread even though I didn't change much in it.

0

Ok i will try it

0

Great now it goes on top of something

0

^Its now working btw

toEulerAnglesXYZ() is your best friend.

part.CFrame = (0,5,0) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ())

This discussion is preserved as it was. New answers, comments, and votes are closed.