Aiming down sights going back and forth

Hello, everyone.
My new aiming down sights system for my gun keeps flicking back and forth. i only have it in a loop since i have other things interacting with the ads such as walking, etc.

video of this happening

local function Aim()

	local ViewModel = workspace.ViewModel :: Model

	if not IsAiming then

		local AimPart = ViewModel:FindFirstChild("AimPart",true)
		IsAiming = true
		local FieldOfView = workspace.Camera.FieldOfView

		local Track2 = Tween:Create(workspace.Camera,AdsInfo,{FieldOfView = FieldOfView/1.5})
		Track2:Play()
		local Camera = workspace.Camera

		repeat
			local Offset = AimPart.CFrame:Inverse() * workspace.Camera.CFrame-- * ViewModel:GetAttribute("Walk"):Inverse()
			local Track = Tween:Create(ViewModel.AimTween,AdsInfo,{Value = Offset})

			Track:Play()

			Track.Completed:Wait()
		until not IsAiming


	else
		print("stopped")
		IsAiming = false
		local FieldOfView = workspace.Camera.FieldOfView
		local Track = Tween:Create(ViewModel.AimTween,AdsInfo,{Value = CFrame.new()})
		local Track2 = Tween:Create(workspace.Camera,AdsInfo,{FieldOfView = FieldOfView*1.5})
		Track:Play()
		Track2:Play()
	end

end
3 Likes

So you need to animation happened once and it stoped at end?
to do it you need to use :Pause function when Track.Completed:Wait() and remove repeat untill loop

2 Likes

If i’m misunderstanded please reply to me about what exacly you’re trying to do.

2 Likes

If you want to it interact to camera you can do tween to new position, starting at current position

2 Likes

i just removed the repeat loop, but now im having another issue. my walk cframe is messing up my aiming down sight script. since the ads is calculating with the walk cframe. when i stop walking the sight is offsetted.

1 Like

Welp, im not good at FPS making and e.t.c, hope you’ll fix this bug. Good luck.

probably because of this :moyai:

		repeat
			local Offset = AimPart.CFrame:Inverse() * workspace.Camera.CFrame-- * ViewModel:GetAttribute("Walk"):Inverse()
			local Track = Tween:Create(ViewModel.AimTween,AdsInfo,{Value = Offset})

			Track:Play()

			Track.Completed:Wait()
		until not IsAiming

probably because of what?

ineedmorecharacters

you’re loop tweening the viewmodel based off the camera cframe until they stop aiming with the scope why do you need to loop it just tween it once then keep it locked like that

i have gun sway and walking cframe which causes the aiming to be offset after you stop moving

Just check the humanoid’s move direction and account for the camera sway. Also if u loop it and tween it while ur scope is in the middle based off the camera cframe it’s gonna tween it away.

i’ve tried doing that, i can’t seem to figure it out. can you help?

	local WalkCFrame = ViewModel.ExtraTween.Value :: CFrame	
	local CameraCFrame = Camera.CFrame		
	local AimPartCFrame = (AimPart.CFrame:Inverse() * WalkCFrame:Inverse())

local Offset = AimPartCFrame * CameraCFrame :: CFrame
		
		print(WalkCFrame.Position)
		print(WalkCFrame:Inverse().Position)
		
		local Track = Tween:Create(ViewModel.AimTween,AdsInfo,{Value = Offset})

		Track:Play()

icba to do cframe math rn The First Person Element Of A First Person Shooter just go look at this tutorial to see what your doing wrong.

ive seen this tutorial many times, and it lacks camera sway, or arm movement while walking. which are what is causing my issues. thanks for the help tho.

What does it mean “middle off the camera is gonna tween it away” i’ve tried it on a normal part and for some reason it behaves as expected, but only doesn’t when i do it on the viewmodel???

im calculating the offset, of the aimpart and the viewmodel. but that doesn’t explain why it’s going backwards.

Oh. Yeah I don’t know then that’s probably just an issue with your viewmodel.

Solution: set it to the viewmodels head instead of camera. for some odd reason the camera makes it really buggy. also the repeat loop is functional.

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