if mvector ~= Vector3.zero then
if cam.FieldOfView == 80 then return end
cam.FieldOfView = cam.FieldOfView + (80 - cam.FieldOfView)*3*dt2
else
if cam.FieldOfView == 70 then return end
cam.FieldOfView = cam.FieldOfView + (70 - cam.FieldOfView)*6*dt2
end```
This is connected to renderstep, the mvector is basically move vector of the player. This is an Fov changing script when you start walking.
#How Can I add easing style onto this lerp
1 messages · Page 1 of 1 (latest)
You can tween it
I'm in render step
oh right
To have easing you must know where about in the lerp you are
why does it have to be in a renderstep though?
I tried
Your lerps don't have a alpha value to have easing
But I run onto a problem
I use the cam Fov to know where I'm
I mean percentage
But It overlaped
with the easing
local fov = 70
local start = 70
local goal = 80
local Tw = game:GetService("TweenService")
for i = 0,1, .1 do
local alpha = Tw:GetValue((fov-start+1)/10,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
fov = start + (goal-start)*alpha
end```
My tes code
using the cam Fov to calculate alpha
It worked
But when I plugin the easing
It overlap
(fov-start+1)/10
Linear alpha can be calculate pretty easy
by math
How to do the alpha of sine with the same approach?
local startValue = 5
local targetavalue = 20
local alpha = 0
while true do
value = (targetValue - startValue) * alpha
print(value)
if alpha == 1 then break end
alpha = math.min(alpha + task.wait(), 1)
end
Umm
Okay
Let me see
But there's definitely a way to get the alpha from the FOV
Do you know it?
Value is fov
Yeah I know
Startvalue is the fov starts at
I'm applying it
And targetvalue is the fov you want
But I just want to know if I could get the percentage given that it have been plug into sine equation
Like this approach
Which calculate where I'm
But not in Sine but in linear equation
(current-start)/(goal-start)
loike that
Then once you done my version you can use the tween service to have different easing styles
Yeah I will use your version
It's more optimized
But I juswt
want to know if a percent calculation like this
exist in sine equation
You want to use sin to calculate the alpha?
Yeah I want to know
Alpha = sin(time)
ummm
Or you can use the tween service
Tween service has sin built into it
this find current alpha
which in linear is very easy to calculate
but it's harder in sine
How do you need the inverse?
Like you know, In linear style, given the current value we can find the alpha
by this equation
But in sine how can we get the alpha given the current value
Iv been scripting for 100 years and iv never needed to get the inverse of sin before
😭
Educational purpose
Search Google I'm sure it will tell you how to do it
Your approach is more optimize right?
🥳
I don't know
I mean it save the alpha
My version is able to tell you where abouts in the lerp you are
we don't need to calculate
my approach need to calculate the alpha base on where we are
Yeah I know
No your version does not have a alpha
Your version never gets to 100%
And your version is not frame rate independent
So your version will get effected by frame rate
local fov = 70
local start = 70
local goal = 80
local Tw = game:GetService("TweenService")
for i = 0,1, .1 do
local alpha = (fov-start)/10+0.1
fov = start + (goal-start)*alpha
end```
this is the original
linear style
it clearly have an alpha
This version will get effected by frame rate
Also your not using the tweenservice
I was just testing
when I plugin I will make sure there's delta
But your version seem better
so nvm
Your delta was not correct
I'll have a video soon showing how to do lerp with correct delta
What do you mean?
I calculate the delta
using my calculator
if I lerp using example 0.3
wait
how to explain this
🤔
oh yeah
No delta mean like 1 second
so
0.3*1
😱
Yeah
But it not effected by framerate
This video is good
DeltaTime. This video is all about that mysterious variable that oh so many game developers seem to struggle with. How to use DeltaTime correclty? I got the answers and hope this video will help to deepen your understanding about how to make frame rate independent video games.
0:00 - Intro
0:34 - Creating The Illusion of Motion
1:11 - Simple Li...
Lets say you have a frame rate of 1 and someone else has a framerate of 2
So the person with a frame rate of 2 will run the loop 2 times and the person with the frame rate of 1 will run the loop once
So if you do
fov = (80 - fov) * dt
Let's say fov starts at 70
Okay
😱
Let's first do 2fps guy
I have commited a crime
(80 - 70) * 0.5 = ???
It's 5
So 5 would be added to fov
So not for is 75
Let's now do it the second time
(80 - 75) * 0.5 = ???
It's 2.5
So we add 2.5
So the player will have a fov of 77.5 after 1 second
Now let's do the player with 1 fps
😱
And that player the fov will be 80 after 1 second
😢
So the player with 1 FPS will go from 70 to 80 after 1 second
And the player with 2 fps will go from 70 to 77.5 after 1 second
So your delta time is not correct in the original message of this post
a car with constant speed
and a car with decreasing speed
thank you for saving my life
Yer
I think it's a simple equation
It's like trying to find the angle based on the length of the triangles side 📐
I mean this
😅
How to get alpha
I mean this as well
Sin is the height of the side of the triangle 📐 based on the angle
So you have to do it the other way around
Yes but I thought easing equation is different?
I'm talking about getting the inverse of sin
Do you know how to represent angle numerically?
Oh no
wait
How to minus angle numerically
Like I have two tan ratio and I can't covert it to angle onto tan inverse
How to turn those two tan ratio to a new tan ratio
which form by minusing two angle
like angle1 - angle2
angle1 = tan -1 (a/b)
😢
Yeah I got it
I learned trig
I never learned trig
wot?
animation?
i learned trig from my dad's old books
just happen to come across it when I was grade 7 or something
Are you hypnotizing me
😅
You trolled me
it more like math.clamp
🤔
So you sucked yourself with a vaccum cleaner
Sound like a good way
to learn math
But that's normally if Im working something out I don't understand
It's hard to see where the dots go
There is min and max
math.max isn't limiting anything it compare
and find largest number
I tested it
Max gets the largest number and min gets the lowest number
Yes
So it don't limit number
It does
yeah
What's smaller 70 or 80
But alpha need math.clamp
Why?
you said math.max can limit
They both limit
Can alpha go below 0
🤑
Yeah
Show me how
local char = script:FindFirstAncestorOfClass("Model")
local root = char:WaitForChild("HumanoidRootPart") :: BasePart
local rs = game:GetService("RunService")
local camera = workspace.CurrentCamera
local fovVelocityRatio = 100 / 20
local minFOV = 90
local maxFOV = 140
local function lerp(s, e, t)
local d = (e - s) * t
return s + d
end
rs.RenderStepped:Connect(function(deltaTime : number)
local velocity = root.AssemblyLinearVelocity * Vector3.new(1, .2, 1)
camera.FieldOfView = lerp(camera.FieldOfView, math.clamp(velocity.Magnitude * fovVelocityRatio, minFOV, maxFOV), deltaTime * 5)
end)
heres my code for FOV, might help
when you lerp it will make something like Quint Out
Yeah
i do lerping
I revert the time revert the state of the car
So when player velocity is zero
it start decrease
oh I understand
But is that faster?
than clamping?
Clamp is like min and max together
Yeah alright
Math.min(Math.max(fov, 30), 80)
This is clamp
But clamp is more optimal then what I showed above
omptimal?
Uses less CPU
If X < min then return min end
If X > max then return max end
Return X