I’m a little of a mediocre scripter.
Example of what I’m talking about: BIGFOOT! - Roblox
Notice as your camera moves as you move your mouse across the screen.
I’m just in a learning phase where I am in no way shape or form ready to script a full fledged game, so I’m sticking to progressing my scripting knowledge. Thanks!
Base the camera on a part, and station the part in the opposite the direction of the mouse (if the mouse is 5 studs away from the part on the X axis, the part will move -5 on the same axis).
The reason why I said the opposite direction is because the camera will point toward the part/direction, not where the mouse is, making it look like the mouse has moved the screen.
Would this work? It takes the mouse’s position and converts it into a start from the center of the screen and makes it have a range from -1 to 1 on each axis.
local RestCF = CFrame.new(0,0,0) -- where the camera should be when the mouse is in the center of the screen
local Camera = workspace.CurrentCamera -- getting the current camera
local UserInputService = game:GetService("UserInputSerivce") -- Getting userinputservice
UserInputService.InputChanged:Connect(function(inputObject, GPE)
local Vector = Vector2.new(inputObject.Position.X/Camera.ViewportSize.X * 2 - 1, inputObject.Position.Y/Camera.ViewportSize.Y * 2 - 1)
if math.abs(Vector.Magnitude) >= Deadzone then -- Define a deadzone, can be 0 if you want no deadzone.
Camera.CFrame = RestCF * CFrame.new(Vector.X * 5, Vector.Y * 5, 0) -- X moves it side to side, Y moves it up and down, and Z moves it forward and backward
-- I am multiplying the vector by 5 to make it move more than just 1 stud, as 1 stud isn't that much movement.
else
Camera.CFrame = RestCF
end
end)
You might find this useful toward the final product you are looking for.
It explains the reasoning for the code, and organizes it as a possible solution to your needs.
local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.CurrentCamera
local DefaultCFrame = Camera.CFrame
local Scale = 200
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) -- update every frame
I do. With your script, it more or less moves the actual camera instead of pointing it.
I’m also commenting out some lines and searching up some things in order to understand better.
while true do
repeat wait() until Active
while Active do
game.Workspace.CurrentCamera.CFrame = game.Workspace. *name of the part you want your camera attached to* .CFrame*CFrame.Angles(math.rad((((mouse.Y-mouse.ViewSizeY/2)/mouse.ViewSizeY))*-100),math.rad((((mouse.X-mouse.ViewSizeX/2)/mouse.ViewSizeX))*-100),math.rad(0))
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
wait()
end
wait()
end