#Lynx sucks at coding

1 messages · Page 1 of 1 (latest)

rain panther
#

here

hardy warren
#
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);```
rain panther
#

ok

#

i get the variable assignment

hardy warren
#

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

rain panther
#

can u explain the order in lerp

#

so i can use it in the future

hardy warren
#

well wait do you understand the inverse lerp part yet?

rain panther
#

and whats the difference between lerp and iverserlerp

hardy warren
#

we're getting there

rain panther
#

ok

hardy warren
rain panther
#

how does it return a number from 0 to 1?

#

why does it

barren flower
# rain panther can u explain the order in lerp

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.

rain panther
#

what tells it to do that

hardy warren
#

it's some simple math

rain panther
#

wth

#

im getting no where

hardy warren
#

THis is the code for inverselerp

#

it's not hard

#

it's jsut this (value - a) / (b - a)

rain panther
#

ohh

#

so it assigns a value of 0 to a bottom value and 1 to a top value

hardy warren
#

yes

rain panther
#

basically connecting them

hardy warren
#

and everything in between

rain panther
#

ok

hardy warren
#

gets linearly mapped to that range of 0-1

rain panther
#

but why the angle at the end of the code

hardy warren
#

because angle is the value we're testing

#

we want to know "where within the rannge of 0 to 180 is our angle?"

rain panther
#

oh

hardy warren
#

is it at the top? or the bottom? How far from top to bottom is it?

rain panther
#

do if it was 90

#

degrees

#

lerp would give our angle a 0.5?

#

value

hardy warren
#

so if it's 90 you get:
(value - a) / (b - a)
(90 - 0) / (180 - 0)
90/180
0.5

#

yes

rain panther
#

because its halfway

hardy warren
#

this is INVERSE lerp

rain panther
#

ok im getting there

hardy warren
#

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)

#

but it's also very simple

#

it's just a + (b - a) * t

rain panther
#

so just a+b*t

#

i mean

#

b*t

hardy warren
#

so in our case: 0 + (24 - 0) * t or just b * t

rain panther
#

forgot bodmas

hardy warren
#

so does that make sense?

rain panther
#

when you just add it

barren flower
#

He's replacing the values for visual clarity

hardy warren
rain panther
#

yeah

#

i get inverse lerp

hardy warren
#

if we did Lerp(50, 100, t) it'd be like: 50 + (100 - 50)t

rain panther
#

but lerp might need a little more thinking for me

hardy warren
#

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

rain panther
#

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

hardy warren
#

ya

rain panther
#

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?

hardy warren
rain panther
#

oops

hardy warren
#

downness would be .5 in your example

rain panther
#

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?

barren flower
#

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

hardy warren
barren flower
#

Vector3.up is NOT the same as transform.up

rain panther
#

how so

barren flower
#

Because, depending on the transformations applied to the transform, it will represent a different direction in world-relative space

rain panther
#

but we're talking about transform.up

#

isnt that just one direction?

#

my 13 year old brain cant understand

hardy warren
#

it's just the direction your snowboarder is facing currently

#

that's all

barren flower
#

Yes, it is best to keep it simple

rain panther
#

whats the point of assinging vector.up

#

isnt global up always the same?

hardy warren
#

assigning it?

#

YOu can't assign it

#

yes it's always the same

rain panther
#

you put it into a variable

hardy warren
#

no i didn't

rain panther
#

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

hardy warren
#

?

rain panther
#

you made a float called angle

hardy warren
#

yes

rain panther
#

and put vector3.angle

#

in brackets

#

youw rote

hardy warren
#

that's the angle between transform.up and Vector3.up

#

I thought we went over this part already

rain panther
#

so its the difference

#

?

#

i must not have understood

hardy warren
#

yes the angle difference between them

rain panther
#

so vector.up represents north

hardy warren
#

yes

rain panther
#

basically

hardy warren
#

gtg help my wife with groceries

#

👋

rain panther
#

bye

barren flower
#

You will eventually understand, in greater detail, what is being discussed.

Do not worry if you do not fully understand it at this time

rain panther
#

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

barren flower
#

Starting early is good

#

I'm proud for you

rain panther
#

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

barren flower
#

Let's break down what each part does

rain panther
#

i get it all

#

besdies lerp

#

the float angle contains the difference between global up and our objects up

#

angles difference

barren flower
#

yeah

rain panther
#

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

barren flower
#

correct

rain panther
#

so if i had 90

#

the value would be o.5

#

0.5*

barren flower
#

Yes

rain panther
#

and then speed

#

dk bout that

barren flower
#

If downness is 0, you get 0
if downness is 1, you get 24

rain panther
#

how long have you been conding for

#

sorry if its a bit personal

barren flower
#

A decent amount of time

#

I don't know how to properly quantify it

#

Because I code off-and-on

rain panther
#

oh

barren flower
#

I still run into API-specific issues

rain panther
#

how much learning time?

rain panther
barren flower
#

It takes a lot of time, but I started late in life, so it might be different for you

#

No

rain panther
#

oh wait

#

no

#

inverselerp tests in on the variable

#

and lerp tests the variable on teh data

barren flower
#

Yes, correct

rain panther
#

ok

#

i get the code

#

😄

#

i get it

#

but

#

idk if i could ever make it

barren flower
#

To be more specific, Lerp's 3rd parameter is the 't' or 'time'

barren flower
#

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

rain panther
barren flower
#

Okay, then disregard

rain panther
#

ty for your help

barren flower
#

It was easier for me to understand it that way, when I first encountered it

rain panther
#

let me run this code

rain panther
#

i mgiht have understood it

#

il never know

#

wish me luck

barren flower
#

Yep, have a good one

rain panther
#

dammit

#

the se2d.speed is always a 0

#

the eular angles are 358

barren flower
#

Can you screenshare?