#How Can I add easing style onto this lerp

1 messages · Page 1 of 1 (latest)

late finch
#
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.
late finch
#

Tween?

#

But it would be glitchy

#

Let me try then

#

wait I can't do that

late finch
lost haven
#

oh right

dusky cedar
#

To have easing you must know where about in the lerp you are

lost haven
#

why does it have to be in a renderstep though?

dusky cedar
#

Your lerps don't have a alpha value to have easing

late finch
#

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?

dusky cedar
#
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
late finch
#

Do you know it?

dusky cedar
#

Value is fov

late finch
#

Yeah I know

dusky cedar
#

Startvalue is the fov starts at

late finch
#

I'm applying it

dusky cedar
#

And targetvalue is the fov you want

late finch
late finch
#

Which calculate where I'm

#

But not in Sine but in linear equation

#

(current-start)/(goal-start)

#

loike that

dusky cedar
#

Then once you done my version you can use the tween service to have different easing styles

late finch
#

It's more optimized

late finch
#

want to know if a percent calculation like this

#

exist in sine equation

dusky cedar
#

You want to use sin to calculate the alpha?

late finch
dusky cedar
#

Alpha = sin(time)

late finch
dusky cedar
#

Or you can use the tween service

late finch
#

is there this equation but in sine version?

#

(current-start)/(goal-start)

dusky cedar
#

Tween service has sin built into it

late finch
#

which in linear is very easy to calculate

#

but it's harder in sine

dusky cedar
#

How do you need the inverse?

late finch
late finch
#

But in sine how can we get the alpha given the current value

dusky cedar
#

Iv been scripting for 100 years and iv never needed to get the inverse of sin before

dusky cedar
#

Search Google I'm sure it will tell you how to do it

late finch
#

Thank you

late finch
#

🥳

dusky cedar
#

I don't know

late finch
#

I mean it save the alpha

dusky cedar
#

My version is able to tell you where abouts in the lerp you are

late finch
#

we don't need to calculate

dusky cedar
#

Alpha is from 0 to 1

#

0 meaning 0% and 1 being 100%

late finch
#

my approach need to calculate the alpha base on where we are

late finch
dusky cedar
#

Your version never gets to 100%

#

And your version is not frame rate independent

#

So your version will get effected by frame rate

late finch
#

this is the original

#

linear style

#

it clearly have an alpha

dusky cedar
#

Also your not using the tweenservice

late finch
#

when I plugin I will make sure there's delta

#

But your version seem better

#

so nvm

dusky cedar
late finch
#

what?

dusky cedar
#

I'll have a video soon showing how to do lerp with correct delta

late finch
#

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

dusky cedar
#

In the original message of this post

#

Delta was not used correctly

late finch
#

Yeah

#

But it not effected by framerate

#

This video is good

dusky cedar
#

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

late finch
#

I calculate delta like this number÷ (1 ÷ 60)

#

Is that wrong?

dusky cedar
#

Let's say fov starts at 70

late finch
#

Okay

dusky cedar
#

For the person running at 2 FPS DT is 0.5

#

For the person running at 1 FPS DT is 1

late finch
#

😱

dusky cedar
#

Let's first do 2fps guy

late finch
#

I have commited a crime

dusky cedar
#

(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 = ???

late finch
#

but

#

(80-70)*1 = 10

dusky cedar
#

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

late finch
#

Yay

#

(80-70)*1 = 10

dusky cedar
#

(80 - 70) * 1 = ???

#

So we add 10

late finch
#

😱

dusky cedar
#

And that player the fov will be 80 after 1 second

late finch
#

😢

dusky cedar
#

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

late finch
#

😢

#

So sad

#

I know now

dusky cedar
#

So your delta time is not correct in the original message of this post

late finch
#

a car with constant speed

#

and a car with decreasing speed

#

thank you for saving my life

dusky cedar
late finch
#

I know you keep your promise suphi

#

🥳

late finch
#

you still remember about the inverse sine thing right?

#

😋

dusky cedar
#

Yer

#

I think it's a simple equation

#

It's like trying to find the angle based on the length of the triangles side 📐

late finch
#

😅

#

How to get alpha

dusky cedar
late finch
#

😱

#

inverse sine equation

#

?

dusky cedar
#

Sin is the height of the side of the triangle 📐 based on the angle

#

So you have to do it the other way around

late finch
dusky cedar
#

I'm talking about getting the inverse of sin

late finch
late finch
#

Oh no

#

wait

#

How to minus angle numerically

late finch
#

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)

dusky cedar
late finch
dusky cedar
#

Sin(angle) = length of the right side of triangle

#

Based on the image above

late finch
#

I learned trig

dusky cedar
#

I never learned trig

late finch
#

😱

#

then how

late finch
#

without trig?

#

😢

dusky cedar
#

I use pictures

#

Well more like animations

late finch
late finch
#

i learned trig from my dad's old books

#

just happen to come across it when I was grade 7 or something

dusky cedar
late finch
#

?

#

😱

dusky cedar
#

The animations don't look like this

#

But it's the closest I could find

late finch
dusky cedar
#

It's more darker not this clear

#

It's like dots moving in a dark room

late finch
#

You trolled me

#

it more like math.clamp

late finch
#

So you sucked yourself with a vaccum cleaner

#

Sound like a good way

#

to learn math

dusky cedar
#

But that's normally if Im working something out I don't understand

dusky cedar
#

It's hard to see where the dots go

late finch
#

is there an alternative to math.clamp that only limit max

#

not min

dusky cedar
#

There is min and max

late finch
#

these gif?

dusky cedar
#

To find the pattern

late finch
#

and find largest number

#

I tested it

dusky cedar
#

Max gets the largest number and min gets the lowest number

late finch
#

So it don't limit number

dusky cedar
late finch
#

no?

dusky cedar
#

Math.min(fov, 80)

#

If fov is 70 what will that return

late finch
#

yeah

dusky cedar
#

What's smaller 70 or 80

late finch
#

But alpha need math.clamp

dusky cedar
late finch
#

you said math.max can limit

dusky cedar
#

They both limit

late finch
#

I just need value between 1 and 0

#

for alpja

dusky cedar
#

Can alpha go below 0

patent brook
#

🤑

late finch
dusky cedar
patent brook
#

how the hell

late finch
#

It doesn't limit

patent brook
#
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

late finch
#

Yeah I know

#

I want to add easing style

late finch
#

I didn't plug delta yet

patent brook
#

^^

dusky cedar
#

Think of alpha like time

patent brook
#

when you lerp it will make something like Quint Out

late finch
patent brook
#

i do lerping

late finch
#

So when player velocity is zero

#

it start decrease

dusky cedar
#

When you add you use min

#

And when you subtract you use max

late finch
#

But is that faster?

#

than clamping?

dusky cedar
#

Clamp is like min and max together

late finch
dusky cedar
#

Math.min(Math.max(fov, 30), 80)

#

This is clamp

#

But clamp is more optimal then what I showed above

late finch
dusky cedar
late finch
#

seem not right

dusky cedar
#

If X < min then return min end
If X > max then return max end
Return X

dusky cedar
#

Min is top

#

Max is bottom

#

Clamp is both

late finch
#

yes

#

I know