Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I change my aiming script to work for an AimPart rather than trying to guess coordinates?

Asked by 5 years ago

Yea I know the title was hard to explain but here's the truth. The way I use aiming in my script is really bad and I was hoping for some suggestions on how to have a aim part on the gun itself so I don't have to do as much work and it can be much more accurate.

The framework looks like this.

local PriCF = p.weaponpos
local PriADS = CFrame.new()

local SecCF = s.weaponpos
local SecADS = CFrame.new()

run.RenderStepped:connect(function()
    guns.Primary:SetPrimaryPartCFrame(cam.CFrame*PriADS)
    guns.Secondary:SetPrimaryPartCFrame(cam.CFrame*SecADS)

    if aiming then
    PriADS = PriADS:lerp(p.aimpos, p.zoomspeed)
    SecADS = SecADS:lerp(s.aimpos, .3)
    uis.MouseIconEnabled = false

    if p.weapontype == "bolt-action" then
        if cam:FindFirstChild(guns.Primary.Name) then
        wait(.2)
        guns.Primary[guns.Primary.Name].Scope.Transparency = 1
            player.PlayerGui.HUD.Scope.Frame.Visible = true
            cam.FieldOfView = p.zoom
            PrimaryPose:Play(.2)
        end
    end


    else
    PriADS = PriADS:lerp(PriCF,.2)
    SecADS = SecADS:lerp(SecCF, .3)
    uis.MouseIconEnabled = true

        if p.weapontype == "bolt-action" then
            guns.Primary[guns.Primary.Name].Scope.Transparency = 0
            player.PlayerGui.HUD.Scope.Frame.Visible = false
            cam.FieldOfView = p.ads
            PrimaryPose:Stop(.3)
        end
    end


end)

The weapon module looks like this Well only a part.

local s = {

weaponname = script.Parent;
weaponpos = CFrame.new(0,-1.5,1.2); -- Position of The Gun In The Cameraz
aimpos = CFrame.new(-1.15,-.9,2);

The problem is I have to change the aimpos so many times just to try to get it straight but even so it's still not accurate. So any suggestions on how I can make it good enough or if I can use a AimPart to make it much easier. Any help would be appreciated.

1 answer

Log in to vote
0
Answered by
Synth_o 136
5 years ago

Alright so I think you are trying to talk about the scope of a gun, and EgoMoose has written a very good article basically explaining everything you want to know so you should check it out:

https://scriptinghelpers.org/blog/the-first-person-element-of-a-first-person-shooter

Ad

Answer this question