Hey @OceanTubez, I’ll see if I could be of some assistance to you real quick.
If you want to move the camera around with the mouse, you would need a few things...
*note:
It may be different from how other people recreate this, but I’m just sharing what my method is. Of course, there are other sources to help you get this effect as well
-
The size of the player’s viewport (can be defined as a global scope, or defined inside the RenderStepped
/Heartbeat
connection. you can get this with workspace.CurrentCamera
)
-
The position of the current mouse (Can be gotten from LocalPlayer:GetMouse()
← found out it’s getting deprecated/unsupported though
-
The middle of the viewport (Can be gotten from dividing the size of the player’s viewport)
-
The max angle of how much you want the mouse to influence
Now, what you’d want to do with this information is to get the difference between the mouse’s position and the middle of the screen (should return a Vector2
, which we’ll use later). Then, what you’d do with that information is to turn the X and Y of the difference into radians by dividing the middle of the corresponding value with it. Like, for example, angleX = math.rad(distX/middleX)
. Hopefully that makes it easier to follow. You then use those values to lerp the camera’ CFrame
to the new rotation. (and just using the camera’s original cframe and adding the new rotation to that)
Doing so, your system might look something like this:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local ScreenSize = Camera.ViewportSize
local ScreenCenter = ScreenSize / 2
local maxAngle = 5
local mouseScale = 150 -- out of 500. giving it a smoother effect when moving the camera
local originalCFrame = Camera.CFrame -- the original CFrame of where the camera should be located.
local firstFrame = true
RunService.Heartbeat:Connect(function(deltaTime) -- you can also use RenderStepped
local mousePosition = UserInputService:GetMouseLocation()
local mouseDiff = ScreenCenter - mousePosition
local xAngle = math.rad(mouseDiff.X / ScreenCenter.X * maxAngle)
local yAngle = math.rad(mouseDiff.Y / ScreenCenter.Y * maxAngle)
local rFrame = CFrame.Angles(yAngle, xAngle, 0)
-- i find it funny how the x and y variables for the camera switch roles
local newCFrame = originalCFrame * rFrame
Camera.CFrame = Camera.CFrame:Lerp(newCFrame, deltaTime * 60 * (mouseScale / 500))
end)
For the camera, there are different things that they could have used to create its animation movement.
They could’ve had the camera been animated in blender to follow the movement of the gun(s), which would mean more camera key frames. This would be easier, since there are resources that allow you to convert a camera’s movement into an animation for the camera.
Or, they could’ve had the camera follow the gun’s motion with a script, and just had different values to have it behave differently. Not something they used, but just as an example:
local cameraKeyframe = {
CFrame = --[[ CFrame ]],
Frame = --[[ number ]],
Instant = --[[ boolean ]],
Subject = --[[ Instance ]],
}
I do recommend you doing the easier way and animating it through blender. IIRC, you’ll need to make a camera humanoid, turn it into a rig for blender, export the animation from blender containing the rig, and have the player’s camera copy the CFrame of the humanoid camera. Here’s a video that could help you out
Camera Blender Tutorial - Roblox Studio - YouTube
Hopefully this helps you create the effect you wanted for your game. If it does, mark this as a solution for others to know as well.
Good luck, and have a blessed day!