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
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:
Set the Orientation Back every time you change the CFrame
Find the position in front of where your block was facing, and set that as the second part of the CFrame.
Use
Position
Instead ofCFrame
.
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.
toEulerAnglesXYZ() is your best friend.
part.CFrame = (0,5,0) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ())