What calculation should I do so that when the player points the viewmodel it gets in the exact position

local bobofsett = CFrame.new()
local cf = CFrame.new()
local uncf = CFrame.new()
local antcameracf = CFrame.new()
local symt = -.3
local currentswaymt = -.3
local aimswaymt = .2
runservice.RenderStepped:Connect(function()
	if loahechos  then
		local rot = camera.CFrame:ToObjectSpace(antcameracf)
		local x,y,z = rot:ToOrientation()
		uncf = uncf:Lerp(CFrame.Angles(math.sin(x) * currentswaymt, math.sin(y) * currentswaymt,0),.1)
		antcameracf = camera.CFrame
		if humanoid.MoveDirection.Magnitude > 0 then
			if humanoid.WalkSpeed == character.Speed.Value and not apunta then
				bobofsett =  CFrame.new(math.sin(tick()* 3)* .06,-humanoid.CameraOffset.Y/4,-humanoid.CameraOffset.Z/7) * CFrame.Angles(0,math.sin(tick() * -2)* -.01,math.cos(tick() * -1)* .01)
			elseif humanoid.WalkSpeed == character.Run.Value and not apunta then
				bobofsett = CFrame.new(math.sin(tick()* 4)* .08,-humanoid.CameraOffset.Y/3,-humanoid.CameraOffset.Z/3) * CFrame.Angles(0,math.sin(tick() * -8)* -.1,math.cos(tick() * -8)* .1)
			end
			if salto then
				bobofsett = bobofsett:Lerp( CFrame.new(0,-1,0) * CFrame.Angles(0,math.cos(tick() * -3)* -.03,0),.1)
			end
		elseif not apunta then
			bobofsett = CFrame.new(math.sin(tick() * 1) * .05,-humanoid.CameraOffset.Y/2,0) * CFrame.Angles(0,math.sin(tick() * -1.2)* -.005,0) 
		else
			bobofsett = CFrame.new(-humanoid.CameraOffset.X,-humanoid.CameraOffset.Y,-humanoid.CameraOffset.Z)
		end
		
		viewmodela:PivotTo(camera.CFrame * uncf * cf * bobofsett )	

		
		if apunta and viewmodela.mira ~= nil and framework.modulerender.Configuration.CanMira then
			local ofset = viewmodela.mira.CFrame:ToObjectSpace(viewmodela.PrimaryPart.CFrame)
		cf = cf:Lerp(ofset,framework.modulerender.Configuration.aimsmoth.Value)
			currentswaymt = aimswaymt
			uis.MouseDeltaSensitivity = 0.4
			
		else
			local ofset = CFrame.new()
			cf  = cf:Lerp(ofset,framework.modulerender.Configuration.aimsmoth.Value)
			currentswaymt = symt
			uis.MouseDeltaSensitivity = 1
		end
		end
end)

Don’t worry about the boolean values ​​but I’ll still tell you what it means

loahechos = --if I load the viewmodel
apunta = --if the player aims the weapon with the mousebutton2
salto=-- if the player jumps in a period of a few milliseconds

Please mention that if you give me a contribution so that the code looks better. I would really appreciate it
By the way, another local script is in charge of changing the CameraOffset when it runs and walks and when it points it doesn’t change it, therefore it doesn’t affect the main local script at all.

what exactly are you trying to do not sure I am understanding the title?

2 Likes

the problem is: when the player runs he shakes a lot, he does it well… but when he aims stop the shake and when he finally gets to aim the scope looks crooked very crooked
is part in aim:

if apunta and viewmodela.mira ~= nil and framework.modulerender.Configuration.CanMira then
			local ofset = viewmodela.mira.CFrame:ToObjectSpace(viewmodela.PrimaryPart.CFrame)
		cf = cf:Lerp(ofset,framework.modulerender.Configuration.aimsmoth.Value)
			currentswaymt = aimswaymt
			uis.MouseDeltaSensitivity = 0.4
			
		else
			local ofset = CFrame.new()
			cf  = cf:Lerp(ofset,framework.modulerender.Configuration.aimsmoth.Value)
			currentswaymt = symt
			uis.MouseDeltaSensitivity = 1
		end

I am very sorry for my English if you did not understand read the part at the beginning and no this issue is not resolved accidentally press the solution button

if there are any doubts you can simply ask me more @Nyonic
edit: Please, I beg you to help me. I don’t need you to make me the code, just guide me to know what I should change or improve.

For me personally, it’s hard to read the code as your variables are named in Spanish. So for this reason, it’s practically unreadable to me.

Is it possible you can rename the variables so it looks easier for people to understand?

2 Likes

in a publication I have explained the variables of the rest are just calculations that have meaningless English names. edit: I know that people do not tell the result because they do not know or because they are lazy, I understand that it is not because of the name of a variable because the one who knows knows knows and you have no excuses and if you have any questions simply ask in the most accurate way possible.

-- viewmodel:PivotTo(camera.CFrame * uncf * cf * bobofsett ) 
-- that part is where I move the viewmodel
--I am going to explain each variable in there
uncf = uncf:Lerp(CFrame.Angles(math.sin(x) * currentswaymt, math.sin(y) * currentswaymt,0),.1)
local ofset = viewmodela.mira.CFrame:ToObjectSpace(viewmodela.PrimaryPart.CFrame)
	cf = cf:Lerp(ofset,framework.modulerender.Configuration.aimsmoth.Value)--this variable changes when the player points the gun otherwise it is 0

--now I go to the values that make the Viewmodel move to simulate the motion, also these are modified before the viewmodel is set.
walk:
	bobofsett =  CFrame.new(math.sin(tick()* 3)* .06,-humanoid.CameraOffset.Y/4,-humanoid.CameraOffset.Z/7) * CFrame.Angles(0,math.sin(tick() * -2)* -.01,math.cos(tick() * -1)* .01)
Run:
bobofsett = CFrame.new(math.sin(tick()* 4)* .08,-humanoid.CameraOffset.Y/3,-humanoid.CameraOffset.Z/3) * CFrame.Angles(0,math.sin(tick() * -8)* -.1,math.cos(tick() * -8)* .1)
			
Jump:
	bobofsett = bobofsett:Lerp( CFrame.new(0,-1,0) * CFrame.Angles(0,math.cos(tick() * -3)* -.03,0),.1)
not aim:
bobofsett = CFrame.new(math.sin(tick() * 1) * .05,-humanoid.CameraOffset.Y/2,0) * CFrame.Angles(0,math.sin(tick() * -1.2)* -.005,0) --it makes a breathing motion when standing still
 and the one I want to improve:

bobofsett = CFrame.new(-humanoid.CameraOffset.X,-humanoid.CameraOffset.Y,-humanoid.CameraOffset.Z)
and the end
 viewmodel:PivotTo(camera.CFrame * uncf * cf * bobofsett ) 

the error was fixed approximately 4.6 hours ago and the error consisted of a missing conditional in the boboofsett part that would allow movement when pointing.

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