I’m trying to recreate Aim punch from CSGO but I have this problem
It works find if your standing still, but it doesn’t if your moving
local TweenService = game:GetService("TweenService")
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local OldHealth = Humanoid.Health
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health < OldHealth then
task.wait(.1)
for _, v in pairs(Humanoid:GetChildren()) do
if v.Name == "headshot" then
local originalCFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(10),0,0)
TweenService:Create(workspace.CurrentCamera, TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {CFrame = originalCFrame}):Play()
end
end
end
OldHealth = Humanoid.Health
end)
its because when the tween plays, the camera cframe tween is going back to is the cframe you set before in the variable called “originalCFrame”
instead of tweening the camera cframe, i suggest you create an offset value and you could offset the cameras X rotation by that offset while the camera is moving in a renderstep or something
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local OldHealth = Humanoid.Health
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Humanoid.Health < OldHealth then
for _, v in pairs(Humanoid:GetChildren()) do
if v.Name == "headshot" then
local originalCFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(10), 0, 0)
for i = 1, 10 do
RunService.RenderStepped:Wait()
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(-1), 0, 0)
end
end
end
end
OldHealth = Humanoid.Health
end)