Hmm works fine with me, remember this is using WalkSpeed
not the characters velocity. Using the characters velocity would still be the same concept.
For me:
walk speed is equal to 16:
walk speed is equal to 25:
Hmm works fine with me, remember this is using WalkSpeed
not the characters velocity. Using the characters velocity would still be the same concept.
For me:
walk speed is equal to 16:
walk speed is equal to 25:
Oh yeah, sorry I didn’t realize that . How would I make it so that it’s based off of the velocity?
Well it would most likely use the same math concept just sorta tweaked. You’d most likely want to use AssemblyLinearVelocity.Magnitude
in place of WalkSpeed.
So like :GetPropertyChangedSignal(“AssemblyLinearVelocity”)???
Also would defaultWalkSpeed be tweaked or remain the same in the formula?
And be sure to get the new Velocity in a while true do loop, or in a function that checks for change in the Velocity.
What do you mean by that?
I’m just confused about how to check the Velocity changing
It’s a Property of a Part.
A value in studs/second.
BasePart.AssemblyLinearVelocity
So in the script you posted:
local humanoid = char:WaitForChild('Humanoid')
local velocity = humanoid.RootPart.Velocity
humanoid:GetPropertyChangedSignal(velocity):Connect(function()
camera.FieldOfView = defaultFOV * (humanoid.WalkSpeed / defaultWalkSpeed)
-- most of this would just be very basic math^**
end)
Not quite… GetPropertyChangedSignal takes a string not a vector3, and the code still changes based on walkspeed so that wouldn’t work either. Something like this should probably do the trick (Reply if there’s a bug I didn’t test it. Code goes in Localscript preferably in startercharacterscripts although startergui works too):
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local max = 120
local min = 70
local dampen = 10
char.PrimaryPart:GetPropertyChangedSignal("Velocity"):Connect(function()
camera.FieldOfView = math.clamp(70 + char.PrimaryPart.Velocity.Magnitude/dampen,min,max) -- tweak around with dampen to increase/decrease the linear change in fov
end)
Edit: You can also use tweeting to make it a bit smoother but it is optional.
Hehe, yeah, it’s a string.
Late night and not a whole lot of experience with the finer points of scripting yet.
I often know the procedures of how to make things work, I just don’t have the skills to type out the lines of code properly so lua can understand what I’m trying to do…
If I’m not mistaken I don’t think properties like Velocity, Position, CFrame fire GetPropertyChangedSignal because of how frequently they change.
I’m pretty sure they do, however in the case they don’t the alternative is just to use renderstepped.
They (at least CFrame, position and orientation) don’t fire when they’re updated via physics, it’ll fire if you manually write to part.CFrame/part.Position etc
Probably Heartbeat would be better, since it fires after the physics frame.
EDIT: Heartbeat, not PostSimulation. Not sure what PostSimulation is there doesn’t seem to be any information regarding it.
I tried this but it didn’t work. No errors in the output, just simply does not work.
Edit: I tried using print statements and it works as expected all until the function.
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
print('Player added.')
local camera = workspace.CurrentCamera
print('Acquired camera.')
local max = 120
local min = 70
local dampen = 10
print('Set locales.')
char.PrimaryPart:GetPropertyChangedSignal("Velocity"):Connect(function()
print('Detected.')
camera.FieldOfView = math.clamp(70 + char.PrimaryPart.Velocity.Magnitude/dampen,min,max) -- tweak around with dampen to increase/decrease the linear change in fov
print('Changed Field of View.')
end)
Just ends after print('Set locales.')
So do as the others have suggested and instead of a function that waits for a property changed signal, use a Heartbeat loop that gets the Velocity each frame of the game playing.
Sorry if this is annoying lool but how do I get the velocity of each frame?? I’m decent at scripting, just RunService and velocity are one of my 2 weaknesses.
Something like this:
local RunService = game:GetService("RunService")
function calculateFov()
camera.FieldOfView = math.clamp(70 + char.PrimaryPart.Velocity.Magnitude/dampen,min,max) -- tweak around with dampen to increase/decrease the linear change in fov
end
RunService.Heartbeat:Connect(calculateFov)
Works like a charm now, thanks so much!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.