Ad
Log in to vote
0

Changing a parts CFrame on the Y Axis?

Asked by 7 months ago

Hey I've asked a lot of questions on CFrame but this answer isn't turning up on the internet. So I have a part that I want to rotate on the global Y axis, not its Euler Angles Y axis or basically, no matter what rotations it x and z axis are at it will turn falt on its Y axis, this is my current script but code but if its x or z are rotated it rotates on an axis that is the y axis of the part rotated. Not sure if this makes sense or not? and there are no errors ~~~~~~~~~~~~~~~~ part = script.Parent while wait() do part.CFrame = part.CFrame * CFrame.Angles(0,1,0) end ~~~~~~~~~~~~~~~~~ This works but if i rotate the part on its x axis it doesnt rotate flat on the y axis How would I do this?

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by 7 months ago
Edited 7 months ago

OK, this works for me. This will create a pre-rotated part and continuously rotate it 10 degrees about the world Y axis once every 1/30th of a second.

local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(15, 1, 15)
part.Position = Vector3.new(0, 11, -11)
part.Rotation = Vector3.new(45, 45, 0)
part.Parent = workspace

while wait() do
    -- Take the position out of the current CFrame to leave only its rotation
    local currentWorldAxisRotation = part.CFrame - part.Position

    -- Get an rotation matrix for the desired rotation
    local additionalWorldAxisRotation = CFrame.Angles(0,math.rad(10),0)

    -- Apply the rotation to the part's current position and rotation. additionalWorldAxisRotation MUST be multiplied first
    part.CFrame = CFrame.new(part.Position) * additionalWorldAxisRotation * currentWorldAxisRotation
end
0
Ive tried this but it changes it on all three axises in a twisty way Wafflecow321 23 — 7mo
0
Oh nvr mind yah this works thanks. Wafflecow321 23 — 6mo
Ad

Answer this question



Ad