I’ve seen a lot of different ways to aim down sights with guns, but most usually require a VM. I was curious to see if there’s any way I can replicate this, but with a normal, non-modified tool.
I’ve attempted to tween the Player’s camera to a part named “AimPart”, though I’m unsure how to do that. If anyone has any feedback or advice, I’d appreciate that. Thanks.
Aim down sight is, at a fundamental level: moving the camera between your sight, and your regular position.
You should post your code so people can help you fix it! Otherwise you’re just asking someone to do it for you - which they aren’t as likely to do, and you won’t learn anything
A VM is a Viewmodel, which is a separate model players use for weapons. I’m using the normal player arms with an ordinary tool.
I’ve been trying to achieve aiming down sights (which, basically, im just wanting to switch between an aimpoint and the players normal camera so they can aim as they please), but to no success.
local CamCF = camera.CoordinateFrame
local function scopeIn()
if gui and isInFirstPerson() and toolEquipped then
if config.ZoomEnabled then
userInputService.MouseDeltaSensitivity = 0.3
camera.FieldOfView = 30
elseif config.ADSCam then
TS:Create(CamCF, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = tool.AimPart.CFrame}):Play()
end
if config.AimDownSights then
tool.FirstPersonArms:SetAttribute("Aiming", true)
end
end
end
Here’s the code I’m currently using. It doesn’t work, spitting out the error “Unable to cast value to object.”
Oh gotcha, so that arms are visible in first-person. This is actually a really old way of hacking around this (going back to like 2008) and there’s a newer way - but I won’t go into that here.
The code you posted looks like it relies on a lot of other variables that aren’t defined in that snippet so it would be hard to figure out what’s wrong. For example, what is “config”?
Is the scopeIn() function being called from somewhere, like a right click mouse button event?
To sum it up:
“config” is the settings script. It’s a module that allows me to change the settings as I wish.
“scopeIn()” is a function that activates when the player presses Right Mouse.
“ZoomEnabled” is a value that determines if the player’s camera zooms in.
“ADSCam” is the value that, if toggled, would tween the players camera to a part named “AimPart” simulating the player aiming down the sights of their weapon.
That being said - this might run, but also still not work. That’s because the Camera.CoordinateFrame is always being updated by the regular camera script (what lets you move it around, zoom in and out, etc).
Unfortunately the 2 best solutions are:
Manage the camera entirely yourself, so you can force it to be where you want each frame (this is not trivial)
Tween the gun to be in the middle of the camera when they ADS, so instead of the camera moving, the gun lifts up
local a = gun:WaitForChild("AimPart").CFrame
local b = viewmodel.Root.CFrame
local aimCF = b:Inverse() * a
aimOffset = CFrame.new(aimCF.X,-aimCF.Y,-aimCF.Z)
dug up this piece of code from an older game, feel free to use
procedurally generates cframes to set a viewmodel into an aiming position