Tweening camera rotation while the player is moving

So, I want to launch player’s camera downwards whenever they jump.

...

humanoid.Jumping:Connect(function(active)
	if not active then return end
	
	local oldCFrame = camera.CFrame
	local tween = TweenService:Create(camera,
		TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
		{
			CFrame = oldCFrame
		}
	)
	tween.Completed:Once(function(pbs)
		tween:Destroy()
	end)
	camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(-30), 0, 0)
	tween:Play()
end)

The issue is the camera is being frozen in place while it is tweening.
Is there any way to avoid that?

5 Likes

Try change camera type to scriptable

1 Like

It already is. I would not be able to change the CFrame if it wasn’t Scriptable.

Did the humanoid.Jumping fire once when haracter jump?

It does. The camera is being yeeted downwards. The problem is it is remaining in the same spot.

run it without this line

camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(-30), 0, 0)

It will not work then. The camera will just freeze in place for 0.5 seconds.
This line is the one that turns the camera downwards.

this might help you

it is essentially animating a part and setting the rotation of that part to the camera each frame

That post is not about Tweening.

Use Springs, create one named LandingSpring and call LandingSpring:Impulse(Vector3.new(1, 0, 0)) when jumping. Then inside the RenderStepped just do:

local landingVelocity = LandingSpring.Position
Camera.CFrame *= CFrame.new(landingVelocity)

What is a Spring and where would I create it?

Look like oldCFrame is same as camera.CFrame so nothing changes
(or changes are to small to see)

1 Like

That’s… the point of oldCFrame
oldCFrame is supposed to be the same as camera.CFrame in order to return to the initial position.

There is no wait or anything so old cframe and camera.cframe are same that why there is no movment bc tween dont need to move it bc its alredy at old cframe

This is why I am :Playing the tween after I set the new camera CFrame.

But start of tween is not updated and is still same as oldCFrame


humanoid.Jumping:Connect(function(active)
	if not active then return end
	
	local oldCFrame = camera.CFrame
	camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(-30), 0, 0)
	local tween = TweenService:Create(camera,
		TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
		{
			CFrame = oldCFrame
		}
	)
	tween.Completed:Once(function(pbs)
		tween:Destroy()
	end)
	tween:Play()
end)

Here’s the module and the docs

Outside the RenderStepped where it’s accessible

Don’t use tween service. The reason this probably isn’t working is because tween service will constantly apply the rotation math to the old camera position.

I would try using a loop and slowly rotate the camera bit by bit while updating the camera. Something like this:

task.spawn()
     for i = 1, 30 do
          camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(-1), 0, 0)
          task.wait()
     end 
end
``

I’m not 100% sure what is going on here in your problem though… if this isn’t what you’re looking for, you may want to send some sort of visual.