How To Create Punch Camera Fling

I tried making the effect where the camera goes a little forward and left/right depending on the punching hand, like a curve. I did it, but the camera is not following the player while doing this.

Here is what I did:

local punchDuration = 0.2
local curveOffset1 = Vector3.new(0.02, 0, 0.7)
local curveOffset2 = Vector3.new(-0.02, 0, -0.7)

-- Punch camera effect

local function punchCamera(hand)
	local startTime = tick()
	local originalCFrame = Camera.CFrame

	local connection
	connection = runService.RenderStepped:Connect(function()
		local t = (tick() - startTime) / punchDuration
		if t > 1 then
			t = 1
			connection:Disconnect()
		end
		
		local firstStep = originalCFrame.Position + originalCFrame:VectorToWorldSpace(curveOffset1)
		local secondStep = originalCFrame.Position + originalCFrame:VectorToWorldSpace(curveOffset2)
	
		-- 2 segment curve using Lerp
		if hand == "left" then
			firstStep = originalCFrame.Position + originalCFrame:VectorToWorldSpace(Vector3.new(-curveOffset1.X, curveOffset1.Y, curveOffset1.Z))
			secondStep = originalCFrame.Position + originalCFrame:VectorToWorldSpace(Vector3.new(-curveOffset2.X, curveOffset2.Y, curveOffset2.Z))
		end
		
		local midpoint = firstStep:Lerp(secondStep, t)
		local newCFrame = CFrame.new(midpoint, originalCFrame.Position + originalCFrame.LookVector)

		Camera.CFrame = newCFrame
	end)

	task.delay(punchDuration, function()
		-- Return back
		local returnStart = tick()
		local returnDuration = 0.3
		local returnConn
		local currentCFrame = Camera.CFrame

		returnConn = runService.RenderStepped:Connect(function()
			local t = (tick() - returnStart) / returnDuration
			if t > 1 then
				t = 1
				returnConn:Disconnect()
			end

			Camera.CFrame = currentCFrame:Lerp(originalCFrame, t)
		end)
	end)
end

I don’t know how to make the camera smoothly follow the player it is while moving and still making that fling

1 Like

you can make the position by using the humanoid’s camera offset.
for the rotation you should be able to set the camera rotation while matching it’s current position.
Method1

you can make it based off an offset to the HRP so it always follows it as it trys to match it.
Method2

I’m not an expert on camera and cframe, so these may not be the greatest. but they should work

Okay, I fixed it. It was actually simple, I just had to pass the camera.CFrame directly instead of storing it in the originalCFrame.
Thank you for help

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