So I have been trying for a long time to add the part of aiming with your gun into my game, now the problem I have that it does this weird teleporting thing instead of smoothly going towards the position it’s supposed to be at.
Here is the code snippet that sets the so called armOffset:
local ADS_Points = {}
for i, instance in equippedItemSlot:GetDescendants() do
if instance:IsA("Attachment") then
if instance.Name == "ADS_Point" then
--if currentSight == instance:GetAttribute("Priority") then
ADS_Points[instance:GetAttribute("Priority")] = instance
--selectedADS_Point = instance
--end
--elseif instance.Name == "ADS_Origin" then
--ADS_origin = instance
end
end
end
local selectedADS_Point = ADS_Points[currentSight or 1]
print(selectedADS_Point, ADS_Points)
if typeof(selectedADS_Point) == "Instance" and selectedADS_Point:IsA("Attachment") then
if aimLerpConnection then
aimLerpConnection:Disconnect()
end
local startTime = tick()
aimLerpConnection = RunService.RenderStepped:Connect(function(deltaTime)
--+ Vector3.new(0, 1.5, 0.625)
--print((tick() - startTime) * (1 / zoomTime), zoomTime)
local selectedADS_Point = ADS_Points[currentSight or 1]
armOffset = (humanoidRootPart.CFrame * CFrame.new(0, 0.5, 0)).Position:Lerp((humanoidRootPart.CFrame * CFrame.new(0, 1.5, 0.625)).Position - selectedADS_Point.WorldPosition, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
--armOffsetL = ADS_origin.WorldPosition:Lerp(ADS_origin.WorldPosition - selectedADS_Point.WorldPosition, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
--armOffsetR = ADS_origin.WorldPosition:Lerp(ADS_origin.WorldPosition - selectedADS_Point.WorldPosition, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
armRotation = Vector3.new() --humanoidRootPart.Rotation:Lerp(humanoidRootPart.Rotation - selectedADS_Point.WorldOrientation, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
--armRotationL = ADS_origin.WorldRotation:Lerp(ADS_origin.WorldRotation - selectedADS_Point.WorldOrientation, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
--armRotationR = ADS_origin.WorldRotation:Lerp(ADS_origin.WorldRotation - selectedADS_Point.WorldOrientation, math.clamp((tick() - startTime) * (1 / zoomTime), 0, 1))
end)
end
And here is the function that sets the C0 and C1 of the arm joints (I had purposefully changed the lookAtPosition)
function updateCharacterRotation(character : Model, lookAtPosition : CFrame, allRotationAxis : boolean?)
if typeof(character) == "Instance" and character:IsA("Model") then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local torso = character:FindFirstChild("Torso")
local head = character:FindFirstChild("Head")
local humanoid = character:FindFirstChildOfClass("Humanoid")
if typeof(torso) == "Instance" and torso:IsA("BasePart") and typeof(head) == "Instance" and head:IsA("BasePart") and typeof(humanoidRootPart) == "Instance" and humanoidRootPart:IsA("BasePart") and typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid") then
local leftarm = character:FindFirstChild("Left Arm")
local rightarm = character:FindFirstChild("Right Arm")
local leftshoulder = torso:FindFirstChild("Left Shoulder")
local rightshoulder = torso:FindFirstChild("Right Shoulder")
local neck = torso:FindFirstChild("Neck")
lookAtPosition = humanoidRootPart.CFrame * CFrame.new(0, 1.5, -1000)
local CameraDirection = humanoidRootPart.CFrame:ToObjectSpace(lookAtPosition).LookVector
if typeof(neck) == "Instance" and neck:IsA("Motor6D") then
local new_c0 = CFrame.new(neck.C0.Position) * CFrame.Angles(3 * math.pi/2, 0, math.pi) --[[* CFrame.Angles(0, 0, -math.asin(CameraDirection.x))]] * CFrame.Angles(-math.asin(CameraDirection.y), 0, 0)
TweenService:Create(neck, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = new_c0}):Play()
end
local cameraDirection = Vector3.new() --(humanoidRootPart.CFrame * CFrame.new(0, 1, 0) * CFrame.new(humanoid.CameraOffset)).LookVector
if typeof(leftarm) == "Instance" and leftarm:IsA("BasePart") and typeof(leftshoulder) == "Instance" and leftshoulder:IsA("Motor6D") then
local lookat = CFrame.lookAt(humanoidRootPart.Position + Vector3.new(0, 1.5, 0) + armOffset, lookAtPosition.Position + cameraDirection) --* CFrame.new(humanoid.CameraOffset)
--local startCFrame = CFrame.new(lookat.Position) --* CFrame.Angles(math.rad(lookat.Rotation.X), math.rad(lookat.Rotation.Y), math.rad(lookat.Rotation.Z))
--lookat = CFrame.new(lookat.Position) * CFrame.Angles(math.rad(humanoidRootPart.Rotation.X), math.rad(humanoidRootPart.Rotation.Y), math.rad(humanoidRootPart.Rotation.Z)) * CFrame.Angles(math.rad(math.clamp(lookat.Rotation.X, -90, 90)), 0, 0)
local cfrm = lookat --[[head.CFrame]] * CFrame.new(-1.5, -1.5, 0) * CFrame.new(0.5, 0.5, 0) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y + -90), math.rad(armRotation.Z)) --* CFrame.new(0, 0, -0.625)
local toCFrame = humanoidRootPart.CFrame:ToObjectSpace(cfrm) --* head.CFrame:ToObjectSpace(CFrame.new(armOffset) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y), math.rad(armRotation.Z)))
--local armCFrame = CFrame.new(armOffset) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y), math.rad(armRotation.Z))
local new_c0 = toCFrame --CFrame.new(armOffset + toCFrame.Position) * CFrame.Angles(math.rad(armRotation.X + toCFrame.Rotation.X), math.rad(armRotation.Y + toCFrame.Rotation.Y), math.rad(armRotation.Z + toCFrame.Rotation.Z)) -- * CFrame.new(0, 0, -0.625)
leftshoulder.C0 = new_c0
--TweenService:Create(leftshoulder, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = new_c0}):Play()
--leftshoulder.C0 = new_c0
end
if typeof(rightarm) == "Instance" and rightarm:IsA("BasePart") and typeof(rightshoulder) == "Instance" and rightshoulder:IsA("Motor6D") then
local lookat = CFrame.lookAt(humanoidRootPart.Position + Vector3.new(0, 1.5, 0) + armOffset, lookAtPosition.Position + cameraDirection) --* CFrame.new(humanoid.CameraOffset)
--local startCFrame = CFrame.new(lookat.Position) --* CFrame.Angles(math.rad(lookat.Rotation.X), math.rad(lookat.Rotation.Y), math.rad(lookat.Rotation.Z))
--lookat = CFrame.new(lookat.Position) * CFrame.Angles(math.rad(humanoidRootPart.Rotation.X), math.rad(humanoidRootPart.Rotation.Y), math.rad(humanoidRootPart.Rotation.Z)) * CFrame.Angles(math.rad(math.clamp(lookat.Rotation.X, -90, 90)), 0, 0)
local cfrm = lookat --[[head.CFrame]] * CFrame.new(1.5, -1.5, 0) * CFrame.new(-0.5, 0.5, 0) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y + 90), math.rad(armRotation.Z)) --* CFrame.new(0, 0, -0.625)
local toCFrame = humanoidRootPart.CFrame:ToObjectSpace(cfrm) --* head.CFrame:ToObjectSpace(CFrame.new(armOffset) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y), math.rad(armRotation.Z)))
--local armCFrame = CFrame.new(armOffset) * CFrame.Angles(math.rad(armRotation.X), math.rad(armRotation.Y), math.rad(armRotation.Z))
local new_c0 = toCFrame --CFrame.new(armOffset + toCFrame.Position) * CFrame.Angles(math.rad(armRotation.X + toCFrame.Rotation.X), math.rad(armRotation.Y + toCFrame.Rotation.Y), math.rad(armRotation.Z + toCFrame.Rotation.Z)) -- * CFrame.new(0, 0, -0.625)
--armOffset
rightshoulder.C0 = new_c0
--TweenService:Create(rightshoulder, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = new_c0}):Play()
--rightshoulder.C0 = new_c0
end
end
end
end
And yes, I’m using the actual arms of the player character and no I’m not gonna use a viewmodel, you can’t convince me to do so.