How to make a gun Aim

Hello,
So i’ve been creating a gun and now I want it to aim and i have no idea on how to do it.
Heres a code:
local runningoffset = CFrame.new(Vector3.new(0,-2.2,0)) * CFrame.Angles(0,math.rad(80),math.rad(60))

local bobbleX = math.cos(tick()  * 6) * .25
local bobbleY = math.abs(math.sin(tick() * 6)) * .25        

local bobble = Vector3.new(bobbleX, bobbleY, 0) * math.clamp(char.PrimaryPart.Velocity.Magnitude,0.1,0.5)
local x = weapon.Assets.Aim.CFrame:Lerp(viewmodel.PrimaryPart.CFrame,script.AimAlpha.Value)
viewmodel:SetPrimaryPartCFrame((game.Workspace.Camera.CFrame + bobble) * script.PositioningOffset.Value)

and this are the components of a gun
image
I’ve been trying this tutorial already but it actually didnt work :frowning:
I’ve been trying for 30 minutes now and it still didnt work.

Please help!

2 Likes

What AIM means?, the arms movement or action when you right click then zoom? , if movement, you have to check angle and then move arms someway, or if zoom,then you have to position camera every frame on client in part position that is your zoom position

Alright I found a solution thanks to EgoMoose,

local offset = viewmodel.PrimaryPart.CFrame:inverse() * weapon.Assets.Aim.CFrame;

offset = offset:inverse()
--viewmodel is a arm
--weapon.Asset.Aim is a weapon's Aim part

Just did a little edit

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