Can anyone tell me how to make a dynamic camera? What I mean by that is lets say the players walkspeed is 16 and when he gets more then 16 walkspeed the camera tweens more back and when the players walkspeed is below 16 the camera tween more in.
Thanks in advance.
you can use FOV and use Humanoid.Changed
Just made this example. Put this in starter player scripts in a local script. When in game, press shift to sprint and see how the camera responds.
local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local ts = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local maxWalkSpeed = 25
function Lerp(min, max, pos)
return min + (max - min) * pos
end
function Update(hum)
local goal = {}
goal.FieldOfView = Lerp(30, 70, hum.WalkSpeed / maxWalkSpeed)
local tweenInfo = TweenInfo.new(.25, Enum.EasingStyle.Quart)
local tween = ts:Create(cam, tweenInfo, goal)
tween:Play()
end
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
Update(hum)
hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
Update(hum)
end)
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
plr.Character.Humanoid.WalkSpeed = 25
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
plr.Character.Humanoid.WalkSpeed = 16
end
end)
I wouldn’t recommend giving entire scripts out to people, I think it would be preferable if @DERKINGIMRING112 gave code beforehand that could then be modified.
Sometimes it’s the best way to learn. Personally, I wouldn’t give entire scripts but I found it very useful when learning scripting if people gave me scripts to look over and see how they work
Thanks gonna look at that when I get home.
I don’t think it is a good way to learn at all. A better way to learn is the op should actually attempt at making the script using tutorials and such before making a post.
If the person who makes the post decides to copy paste the script without learning how it works then they’re at fault (not the person who posted the script)
Everyone learns differently and seeing examples of how to use certain functions, strategies, and terms in scripts can be super helpful
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local function onWalkSpeedChanged(walkSpeed)
if walkSpeed > 16 then
local newCameraOffset = camera.CoordinateFrame * CFrame.new(0, 0, -5)
camera:TweenTo(newCameraOffset, "Out", "Quad", 0.5, true)
elseif walkSpeed < 16 then
local newCameraOffset = camera.CoordinateFrame * CFrame.new(0, 0, 5)
camera:TweenTo(newCameraOffset, "Out", "Quad", 0.5, true)
end
end
camera.CameraSubject = humanoid
humanoid.WalkSpeedChanged:Connect(onWalkSpeedChanged)