I'm trying to add aiming to my viewmodel but it keeps dissappearing

  1. I’m trying to make it so when aiming boolvalue is true then the viewmodel will aim

  2. issue is that when i set the cframe and everything then the gun just dissappears when i hold mouse left button

  3. i searched and looked at many posts but none of that works for me

here is my code:
— the part where the vm gets to camera —
vm:SetPrimaryPartCFrame(camera.CFrame
* CFrame.Angles(sway.y,-sway.x,-sway.x)
* CFrame.Angles(0,0,strafing.z)
* CFrame.new(walk.x,walk.y,walk.z)
* Offset
* aimCFrame)
— the offset cframe script that is under the if aminig true thing —
if Aiming then
local Dist = Camera.CFrame:ToObjectSpace(vm.AimPart.CFrame)
aimCFrame = CFrame.new(0,-1.3,0)
Offset=CFrame.new(Dist.X,Dist.Y,0)
else
aimCFrame = CFrame.new()
Offset = CFrame.new()
end


i have no idea how to fix it

first of all, use three backticks (```) to encase code blocks, also can you take a video of whats happening?

example

print "hi"

dissappears every time i aim

for cframing things like viewmodels I would suggest printing their final cframe on update, as its probably not dissapearing, its probably being set to NaN, NaN, NaN or being set really far away due to goofy ahh cframe math

edit: also whats the difference between aimCFrame and Offset? they look like they are achieving essentially the same thing except one’s moving it to the AimPart and one’s moving it 1.3 studs upwards

Okay i tried it and the CFrame was flying around random numbers (sometimes the first number was 1345 and a half second after it was -59614), but how does other fps games aiming work? i mean i have no idea how to make it aim without flying away

i have changed that so now its just the aimpart cframe

edit: no longer using the offset thing

is your FirePart a Part or an Attachment?

its Part welded to the guns grip (in the viewmodel model)

OHHHHHHHHHHHHHHHHHHH
YOU’RE SETTING DIST AS AN OBJECT SPACE OF THE CAMERA

Set aimCFrame to vm.PrimaryPartCFrame:ToObjectSpace(vm.AimPart.CFrame) (or that inversed idk)

if you set it to the camera its going to have an exponential effect every frame

Its giving me this error
: ToObjectSpace is not a valid member of Part “Workspace.Camera.v_HK416 A5.HumanoidRootPart”

sorry forgot a period lol
vm.PrimaryPart.CFrame:ToObjectSpace(vm.AimPart.CFrame)

this references from the VM primary part instead of a goofy exponential dissapearance with the camera

i tried it but it looks like this when i aim

edit:succes is that i doesnt fly away

vm.PrimaryPart.CFrame:ToObjectSpace(vm.AimPart.CFrame):Inverse()

for me just try everything with cframe math lol

(if that doesnt work swap vm.PrimaryPart.CFrame and vm.AimPart.CFrame and try it inversed and normal)

Edit: if my math is right, it should definitely be
vm.AimPart.CFrame:ToObjectSpace(vm.PrimaryPart.CFrame)

1 Like

Thank you so much it works finally i just gotta adjust the aimpart postion a bit but it works!

also i got a small issue is that the aim is too snappy , what is the best way to make it smoother?

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