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

How could I keep the CFrame rotation matrix, when I change a parts position?

Asked by 5 years ago

I have a gate script that moves it up and down, but it seems to set the orientation back to 0,0,0 instead of 0,90,0. Any help? Here is the Server Script:

local TweenService = game:GetService("TweenService")
local door1 = script.Parent.Parent.Parent.Part1
local tweeningInformation = TweenInfo.new(
    2,   
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local door1Open = {CFrame = CFrame.new(-161.498, 15.143, -125.72)}
local door1Close = {CFrame = CFrame.new(-161.498, 5.666, -125.72)}
local tween1open = TweenService:Create(door1,tweeningInformation,door1Open)
local tween1close = TweenService:Create(door1,tweeningInformation,door1Close)
 local open = false
script.Parent.ClickDetector.MouseClick:Connect(function()
    if not open then 
    open = true
    tween1open:Play()
    else
    tween1close:Play()
open = false
    end
end)
0
didnt you post an essentially identical question a day ago theking48989987 2147 — 5y
0
Yeah but you didn't answer my question. I could take it down. Mrmonkeyman120 65 — 5y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

This should work since your rotation matrix starts out with zeros:

I tested it out with two parts applying the rotation of the oldPart to the newPart, but idea's still the same.

newPart = game.Workspace.newPart --part you want to apply the rotation to
oldPart = game.Workspace.oldRotatedPart --Part you want to keep the rotation of 

rotation = (oldPart.CFrame - oldPart.CFrame.p) -- subtract position to get the rotation
newPart.CFrame = newPart.CFrame * rotation --apply rotation to part you want to be rotated

0
I don't want anything to rotate, I want everything NOT to rotate. Mrmonkeyman120 65 — 5y
0
Yeah, your script is setting the rotation to zero because you're making a new CFrame without specifying the rotation. This should make the new rotation that you just made and rotate it to the old rotation you wanted in the first place. Not sure if that's what you wanted. royaltoe 5144 — 5y
0
Either that or you could include the old rotation into the new CFrame values on lines 11 and 12 royaltoe 5144 — 5y
0
Hi, you've been online since I last posted, but you seem to not have the question answered. Do you still need this answer to be answered or does the code above work? royaltoe 5144 — 5y
Ad

Answer this question