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

How to rotate camera with tweenservice?

Asked by 3 years ago

So I'm working on an exit system that moves the camera to a spot when you click exit

My code right now:

script.Parent.MouseButton1Click:Connect(function()
    --// Main variables
    local variablestorage = script.Parent.Parent.Parent.Parent.DealerDetector.Main
    local campart2 = variablestorage.CamPart2.Value
    --// Tweening camera
    local TweenService = game:GetService("TweenService")
    local camera = workspace.CurrentCamera

    camera.CameraType = Enum.CameraType.Scriptable

    local tween = TweenService:Create(camera,TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{CFrame = CFrame.new(campart2.Position),Focus = CFrame.new(10, 0, 0)})

    tween:Play()
end)

This tweens it to the part, however the rotation is off, even though the front part of the object is facing the right way.

Here's what it looks like: https://gyazo.com/9e976fcade075fc1591e05f25bffaf91

Here's a image depicting how the parts are positioned: https://cdn.discordapp.com/attachments/718624178353340417/799670567526858792/unknown.png

Why does the rotation change? How do I fix it?

0
Make sure the part is facing the front, and is straight. Dovydas1118 1495 — 3y
0
It is which I showed in the example. tgarbrechtALTacc 20 — 3y
0
Maybe use the CFrame of campart2 instead of making a new one, like: CFrame = campart2.CFrame Y_VRN 246 — 3y
0
Using CFrame.new creates a CFrame without rotation, and CFrame.Angles makes a rotated CFrame from radians, without the position. Multiplying the two gives a CFrame with both position and rotation. Y_VRN 246 — 3y

Answer this question