Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cframe resets rotation. How do i fix?

Asked by 6 years ago

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

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago
Edited 6 years ago

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

  2. Find the position in front of where your block was facing, and set that as the second part of the CFrame.

  3. 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.

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. Houlardy642 28 — 6y
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. ax_gold 360 — 6y
0
Ok i will try it asd1232468 5 — 6y
0
Great now it goes on top of something asd1232468 5 — 6y
0
^Its now working btw asd1232468 5 — 6y
Ad
Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

toEulerAnglesXYZ() is your best friend.

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

Answer this question