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

How do you keep rotation?

Asked by
Zerio920 285 Moderation Voter
9 years ago

I can change the CFrame of a brick by using

part.CFrame = CFrame.new(blah,blah,blah)

But the rotation of the brick gets messed up. I can always do

part.CFrame = CFrame.new(blah,blah,blah) * CFrame.Angles(blah,blah,blah)

But what if I only want to change the rotation of one axis and keep the rest the same? The brick's rotation constantly changes so don't suggest "put the same angle in the other two axis and change the third one".

2 answers

Log in to vote
1
Answered by 9 years ago

Use CFrame:toEulerAnglesXYZ(). Example:

local part = game.Workspace.Part
local x,y,z = part.CFrame:toEulerAnglesXYZ()

part.CFrame = CFrame.new(0,10,0) * CFrame.Angles(x,math.rad(45),z)

But you probably could have found that out if you researched the wiki toroughly enough..

EDIT: Though this answer is correct, BlueTaslem's answer is likely to be less expensive.

Ad
Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Subtract the position from the CFrame, and then add the new position.

This involves no special extra work; it's much simpler and more elegant to do -- you should only rarely have to invoke :toEulerAngles

local orientation = part.CFrame - part.Position;

part.CFrame = orientation + Vector3.new( blah, blah, blah );

Answer this question