Glitches in first person animation, help me

What do you want to achieve?
I want to run the script

What is the issue?
I want to fix the problem, there is an error in the camera or in the player or in the animation

What solutions have you tried so far?
I tried to change the animation and fix some bugs in the script but I can’t find the error

this is the script
There are two animations, one from the npc(“United_LxE”) and the other from the user. The camera is in scriptable and it’s in the character’s cframe, but the head spins when I put it, that’s the only problem.
I don’t know much about scripts, you can do some scripts too many or others with errors

local RunService = game:GetService("RunService")

local Character = script.Parent
local Animation = game.Workspace.United_LxE.Script:WaitForChild("Dances")
local Anim = game.Workspace.proxxxi:WaitForChild("Animation")

local player = game.Players.LocalPlayer
local Head = player.Character.Head
local CamPart = workspace.Model1.Cameraaa
local Camera = workspace.Camera

wait(3)
local Run = nil 
local function Cinematica(Bool)
	if Bool == true then
		Camera.CameraType = Enum.CameraType.Scriptable
		Run = RunService.Stepped:Connect(function()
			local hum = player.Character:WaitForChild("Humanoid")
			local loadAnim = hum.Animator:LoadAnimation(Anim)
			loadAnim:Play()
			Camera.CFrame = Head.CFrame
		end)
	else
		Run:Disconnect()
		Camera.CameraSubject = Character.Humanoid
		Camera.CameraType = Enum.CameraType.Scriptable
	end
end

Cinematica(true)
Animation.Stopped:Connect(function()
	Cinematica(false)
end)

Hello! May I ask what the animation is supposed to look like?

I explain, the animation is executed in the player and the camera is positioned on the head, and that the camera follows the direction of the head according to the animation where it turns, I try to make an animation in the first person.

You could try this:

	local baseCFrame = Character.HumanoidRootPart.CFrame + Character.HumanoidRootPart.CFrame.UpVector * (Character.HumanoidRootPart.Size.Y / 2)
	local objectSpacePosition = baseCFrame:pointToObjectSpace(Mouse.Hit.Position)

	--local horizontalAngle = -(math.atan2(-objectSpacePosition.x, -objectSpacePosition.z))
	local verticalAngle = (math.atan2(objectSpacePosition.y, math.sqrt(objectSpacePosition.x^2 + objectSpacePosition.z^2)))

	return verticalAngle
end

function updateAim()
	-- Some code to get the aimTrack, set it up, play it, handle aiming/aiming down sights, etc.

	local lookAngle = getLookAngle()
	-- A few magic numbers are required to convert from radians to a 0-1 interval.
	local aimTimePos = (lookAngle + math.pi/2) * (aimTrack.Length / math.pi)

	aimTrack.TimePosition = aimTimePos
end
2 Likes

Sorry for the delay in responding I had some problems, Hmm how could you place the script correctly in mine I see that you put a vector and angle.