Hey!, Is there a way to rotate my camera angle in roblox?
7 Likes
I think Roblox documentation will help.
4 Likes
Ik but i searched and i dont find anything that i like
1 Like
use CFrame.fromOrientation
/CFrame.fromEulerAnglesXYZ
or CFrame.lookAt
Can u please tell me an example of how to use it? (Im a new developer)
a localscript inside starterplayerscripts that makes the player’s camera look in a random direction:
function lookRandomly()
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local tempPart = Instance.new("Part")
tempPart.CFrame = CFrame.new(Random.new():NextInteger(1, 1000), player.Character.Head.CFrame.Position.Y, Random.new():NextInteger(1, 1000))
tempPart.Parent = workspace
camera.lookAt(camera.CFrame.Position, tempPart.CFrame.Position)
end
task.wait()
lookRandomly()
this example may be too advanced, but try to take a look
take a look at this
local activationKey = Enum.KeyCode.V
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local tweenInfo1 = TweenInfo.new(
2,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out
)
local currentTweenThread
local function tweenLoop(startRotation, endRotation, tweenInfo)
local tweenStartMoment = os.clock()
local normalizedTimeSpent = 0
while normalizedTimeSpent <= 1 do
local lerpAlpha = TweenService:GetValue(normalizedTimeSpent, tweenInfo.EasingStyle, tweenInfo.EasingDirection)
local interpolatedRotation = startRotation:Lerp(endRotation, lerpAlpha)
Camera.CFrame = interpolatedRotation + Camera.CFrame.Position
RunService.RenderStepped:Wait()
normalizedTimeSpent = (os.clock() - tweenStartMoment) / tweenInfo.Time
end
currentTweenThread = nil
end
local function tween()
if currentTweenThread ~= nil then
task.cancel(currentTweenThread)
end
currentTweenThread = task.spawn(tweenLoop, Camera.CFrame.Rotation, Camera.CFrame.Rotation * CFrame.Angles(0, 0, math.rad(45)), tweenInfo1)
end
UserInputService.InputBegan:Connect(function(input, inchat)
if input.KeyCode == activationKey then
tween()
end
end)
1 Like
Thanks! It worked! Very useful
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.