Ad
Log in to vote
0

Camera lock rotation to mouse, like in shift lock mode?

Asked by 4 days ago
Edited 3 days ago

The title sounds odd I know.

I have a camera script and I am trying to make a custom 3rd person camera script. Like the one roblox has when you enable shift lock but I am making my own because theres is a little... Well lets say limiting.

I am trying to figure out how to make the camera rotate with the mouse like in shift lock mode.

Heres my script so far.

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

repeat
    wait()
until player.Character

local character = player.Character
local player_Torso = character.Torso

camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = player_Torso

game:GetService("RunService").RenderStepped:connect(function()
    camera.CFrame = CFrame.new(player_Torso.CFrame.X + 2, player_Torso.CFrame.Y + 2, player_Torso.CFrame.Z + 4)
    camera.FieldOfView = 90 
end)

Thank you for your time. :)

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
mattscy 51
4 days ago

CFrame can have two arguments, which are its position and the lookAt facing direction. If you set the facing direction to the lookVector of the torso after it is offsetted from the position, it should point in the same direction that the torso is.

local cameraPosition = Vector3.new(player_Torso.Position.X + 2, player_Torso.Position.Y + 2, player_Torso.Position.Z + 4)
camera.CFrame = CFrame.new(cameraPosition, cameraPosition + player_Torso.CFrame.lookVector)
0
I mean like, you know how ROBLOX has a shift lock mode. I wanted to lock the characteres lookvector and the cameras look vector the the mouse or center of the screen GottaHaveAFunTime 55 — 3d
0
Then you could use game.Players.LocalPlayer:GetMouse().Hit.p as the lookAt argument. mattscy 51 — 3d
Ad

Answer this question



Ad