I’m practicing with CFrame by creating a car pedal system, but whenever I tween the CFrame.Angles it always looked bad until I used ToWorldSpace() which worked until it didn’t. You see, what ToWorldSpace() does, is it adds to the current angle instead of a fixed orientation. I have searched for a while and can’t find a simple solution.
Code:
--Services
local UIS = game:GetService("UserInputService")
local CAS = game:GetService("ContextActionService")
local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")
--Player
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
local humRoot = char.HumanoidRootPart
--Camera
local cam = game.Workspace.CurrentCamera
local camBone = game.Workspace:WaitForChild("CamBone")
cam.CameraType = Enum.CameraType.Scriptable
--Parts
local gasPedal = game.Workspace.Accelerator
local brakePedal = game.Workspace.Brake
local clutchPedal = game.Workspace.Clutch
--Main
cam.CFrame = camBone.CFrame
cam.FieldOfView = 90
local x, y, z = gasPedal.PrimaryPart.CFrame:ToEulerAngles() -- this is just here because of testing, it is not currently being used
print(gasPedal.PrimaryPart.Orientation)
local function gasDown(actionName, inputState)
if actionName == "GasPressed" and inputState == Enum.UserInputState.Begin then
print("Input Began")
local camTween = TS:Create(cam, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {FieldOfView = 100})
local gasTween = TS:Create(gasPedal.PrimaryPart, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = gasPedal.PrimaryPart.CFrame:ToWorldSpace(CFrame.Angles(math.rad(-20), 0, 0))})
--camTween:Play()
gasTween:Play()
elseif actionName == "GasPressed" and inputState == Enum.UserInputState.End then
print("Input Ended")
local camTween = TS:Create(cam, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {FieldOfView = 90})
local gasTween = TS:Create(gasPedal.PrimaryPart, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = gasPedal.PrimaryPart.CFrame:ToWorldSpace(CFrame.Angles(math.rad(20), 0, 0))})
--camTween:Play()
gasTween:Play()
end
end
CAS:BindAction("GasPressed", gasDown, false, Enum.KeyCode.W)
RS.RenderStepped:Connect(function()
print(gasPedal.PrimaryPart.Orientation)
end)

