Motor6D adjusting value instead of setting it

I’m currently trying to add aiming down sights to my weapon system I’ve started working on recently. My issue is weird Motor6D behavior that I’ve encountered, when I’m trying to adjust Arms rotation accordingly to difference between Y axis of Camera and Torso LookVectors (Angle variable) - the arm starts spinning instead of just moving to the desired angle.

Function caller:

RenderConnection = RunService.RenderStepped:Connect(function() AimEvent:FireServer(Camera.CFrame.LookVector.Y - Character.Torso.CFrame.LookVector.Y, State) end)

Function on server that’s supposed to rotate arms:

AimEvent.OnServerEvent:Connect(function(Player, Angle, State)
	local Character = Player.Character

	if State == true then
		if Aiming == false then
			Aiming = true	
			AimAnimation:Play()
			IdleAnimation:Stop()
		end

		local CurrentC0 = Character.Torso["Right Shoulder"].C0
		local X, Y, Z = CurrentC0.Rotation:ToEulerAnglesXYZ()

		local NewRotation = CFrame.Angles(X, Y, Angle)
		local NewC0 = CFrame.new(CurrentC0.Position) * NewRotation

		Character.Torso["Right Shoulder"].C0 = NewC0
	elseif State == false and Aiming == true then
		Aiming = false
		AimAnimation:Stop()
		IdleAnimation:Play()
	end
end)

Spinning:

I’m using Angle as Z instead of Y because animation thats also in place during ADS seems to be replacing these 2 with each other.

When using Angle as different axis it works but the arm isnt factually moving on the right axis (For example moves right and left when used on Y).

It seems to me like the Motor6D is getting adjusted by value instead of set to value each iteration but I have no idea how thats possible. Any help appreciated!

1 Like

This is something I came across once, so I believe it’s something to do with the Current position. You’re making it spin because it’s changing depending on what it is if that makes sense. It’s like adding a number by 1 over and over. It just makes it keep changing. Instead, you should change it to a locked number.

What you’re doing:
1+1

What you should be doing:
2

The fix would be defining this part outside of the render stepped event, and then every render step updates the C0 to this variable

I hope this makes sense, if not, please reply!

2 Likes

You mean I should keep the default ADS CFrame in some variable and then just adjsut it by current Angle each time that the function is called, yes?

1 Like

Yes, exactly! Let me know if it works.

2 Likes

Works! Thanks for the help :DD

1 Like

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