How to make a camera move in the menu screen

I tried to find a game to give an example on my question, but I couldn’t find any.

Basically, when your camera’s CFrame is locked onto a part, your camera can also look at where your mouse is pointing, but not directly at it, just kind of shift a bit.

In this video I made the camera’s CFrame look at my mouse, but it looks directly at it, which is not what I want, I just want it to partially look, and to give it a limit to how much it can rotate:

As you can see, the camera rotates to where the mouse is pointing, but it keeps on following it, and there’s no limit (i can look at the opposite direction).

This is my code:

local setCameraCFrame = RuS.Heartbeat:Connect(function(frame)
    camera.CFrame = CFrame.lookAt(camera.CFrame.Position,mouse.Hit.Position)
end)

How do I do this?

2 Likes

Try using BodyGyro, It will work I think.

1 Like

For the camera?

It’s not related to physics, you know.

So what do you want the limit to be?

1 Like

I’ll try to find a game which has the same kind of thing I want to be doing. Hang on…

2 Likes

I can’t find any games in my Continue section, even though I remember playing one or two games with this.

I’ll try to explain…?

Basically, your camera is locked onto a part with CFrame, but I want it to partially look at where the player’s mouse of pointing, so if my mouse is at the bottom left of the screen the camera will be looking slightly to the bottom left, with some kind of limit.

I think I found a post similar to what I want to achieve. Can someone help explain?

I would check this out if I were you, this should give you what you’re trying to achieve:

1 Like

Try this (found it in this post and did some tweaking)

local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

--Change these to be camera spot

Camera.CameraSubject = game.Workspace:WaitForChild('Part') 

Camera.CFrame = game.Workspace:WaitForChild('Part').CFrame



local DefaultCFrame = Camera.CFrame
local Scale = 20 --Lower means stronger

function Update()
	-- get the center of the screen
	local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
	-- get the movement (it's in studs, and the mouse properties are in pixels, so you want to divide it by your scale to not move the camera really really far)
	local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, ((-Mouse.Y)-Center.Y)/Scale, 0)
	-- CFrame * CFrame makes it work the same regardless of rotation, where addition just makes it work for one direction
	Camera.CFrame = DefaultCFrame * CFrame.new(DefaultCFrame.p + MoveVector)
end

game:GetService("RunService").RenderStepped:Connect(Update)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.