#Lynx sucks at coding
1 messages · Page 1 of 1 (latest)
float angle = Vector3.angle(transform.up, Vector3.up);
// now do your math with angle
float downness = Mathf.InverseLerp(0, 180, angle);
float speed = Mathf.Lerp(0, 24, downness);```
ok so this part:
float downness = Mathf.InverseLerp(0, 180, angle);
it's going to take that number between 0 and 180 and return a number between 0 and 1
so if you give it:
0 -> 0
45 -> 0.25
90 -> 0.5
135 -> 0.75
180 -> 1
that's all inverseLerp does
well wait do you understand the inverse lerp part yet?
and whats the difference between lerp and iverserlerp
we're getting there
ok
Do you understand this? #963450476618194974 message
I'll leave this here, so that you can understand why Lerp works the way it does
Linear Interpolation of the path defined by r<t> is
r<t> = (x0 + t*(x1 - x0), y0 + t*(y1 - y0), z0 + t*(z1 - z0))
This looks confusing, but if you input 0 for t, you get
r<0> = (x0, y0, z0)
and if you input 1, you get
r<1> = (x1, y1, z1)
which means, the range 0 <= t <= 1 defines the path between points r<0> and r<1>
Inputting other values of t will get you other points along the path defined by the two points
This is interpolating between points, though, and interpolation is not limited to points.
You can interpolate between directions and rotations, as well.
what tells it to do that
the code inside the function
it's some simple math
THis is the code for inverselerp
it's not hard
it's jsut this (value - a) / (b - a)
yes
basically connecting them
and everything in between
ok
gets linearly mapped to that range of 0-1
but why the angle at the end of the code
because angle is the value we're testing
we want to know "where within the rannge of 0 to 180 is our angle?"
oh
is it at the top? or the bottom? How far from top to bottom is it?
because its halfway
this is INVERSE lerp
ok im getting there
ok NOW thjat we have our 0.5
Lerp does the opposite
it takes that number and again maps it to a new range
so:
0 -> 0
0.25 -> 6
0.5 -> 12
0.75 -> 18
1 -> 24
because we used Lerp(0, 24, t)
and if you want to see the code for Lerp it's here https://github.com/Unity-Technologies/UnityCsReference/blob/c84064be69f20dcf21ebe4a7bbc176d48e2f289c/Runtime/Export/Math/Mathf.cs#L222
but it's also very simple
it's just a + (b - a) * t
so in our case: 0 + (24 - 0) * t or just b * t
forgot bodmas
so does that make sense?
whats the point of the minues
when you just add it
He's replacing the values for visual clarity
because we multiply by t before the add
if we did Lerp(50, 100, t) it'd be like: 50 + (100 - 50)t
but lerp might need a little more thinking for me
conceptually just think of a line between a and b
and if t is .5, you get the number halfway along that line
if it's 1, you get b
if it's 0 you get a
and so on for every number between 0 and 1
ok
so
vector3.angle is our global up
and transform is our objects up
inverse lerp connects two numbers together
by assigning a number to the numbers
first number gets 0
second gets 1
ya
and it tests this bond on our angles value
slowly getting there
is this data stored anywhere
so if we had 90 degrees
and it tested with angle to make 0.5
does that get stored?
just in that local variable I called "downness" in my code
oops
downness would be .5 in your example
didnt see that
float angle = Vector3.angle(transform.up, Vector3.up);
// now do your math with angle
float downness = Mathf.InverseLerp(0, 180, angle);
float speed = Mathf.Lerp(0, 24, downness);
math f is just used for maths functions right?
isnt vector3.up the same as transform.up?
To clarify--
Vector3.Angle gets you the angle between two vectors
Vector3.up is the global up vector
transform.up is the local up vector of the transform, transformed into world-relative space
transform.up is equivalent to the following--
Vector3 ourTransformUp = transform.localToWorldMatrix * Vector3.up
It's the class Unity shoved all these functions into yes https://docs.unity3d.com/ScriptReference/Mathf.html
Vector3.up is NOT the same as transform.up
how so
Because, depending on the transformations applied to the transform, it will represent a different direction in world-relative space
but we're talking about transform.up
isnt that just one direction?
my 13 year old brain cant understand
Yes, it is best to keep it simple
you put it into a variable
no i didn't
float angle = Vector3.angle(transform.up, Vector3.up);
// now do your math with angle
float downness = Mathf.InverseLerp(0, 180, angle);
float speed = Mathf.Lerp(0, 24, downness);
3rd line
?
you made a float called angle
yes
that's the angle between transform.up and Vector3.up
I thought we went over this part already
yes the angle difference between them
so vector.up represents north
yes
basically
bye
You will eventually understand, in greater detail, what is being discussed.
Do not worry if you do not fully understand it at this time
ty for your help
il try to figure it out
i want to do game design when i grow up
hope i'd do well
ty
i tyink it get this code though
float angle = Vector3.angle(transform.up, Vector3.up);
// now do your math with angle
float downness = Mathf.InverseLerp(0, 180, angle);
float speed = Mathf.Lerp(0, 24, downness);
besides normal lerp
Let's break down what each part does
i get it all
besdies lerp
the float angle contains the difference between global up and our objects up
angles difference
yeah
downess gives 0 a value of 0
and 180 a value of 1
connecting them
giving values according to everything in betweem
and tests it on angle
correct
Yes
If downness is 0, you get 0
if downness is 1, you get 24
A decent amount of time
I don't know how to properly quantify it
Because I code off-and-on
oh
I still run into API-specific issues
how much learning time?
isnt that what inverselerp does
It takes a lot of time, but I started late in life, so it might be different for you
No
oh wait
no
inverselerp tests in on the variable
and lerp tests the variable on teh data
Yes, correct
To be more specific, Lerp's 3rd parameter is the 't' or 'time'
so at 'time' 0 (so, no time has elapsed), you didn't go anywhere, so you return the first value
at 'time' 1 (basically, the full duration of time has elapsed), you finally got to the end, so you return the second value
I get it but that sounds more complicated
Okay, then disregard
ty for your help
It was easier for me to understand it that way, when I first encountered it
let me run this code
if you toldme it first
i mgiht have understood it
il never know
wish me luck
Yep, have a good one
Can you screenshare?