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