#vectors

1 messages · Page 1 of 1 (latest)

stark oasis
#

please share the whole script in here

vestal girder
#

again I am not trying to solve my problem, I am trying to understand why my understanding is wrong

#

obviously I want to solve my problem but I can't solve it myself if you just tell me the answer

stark oasis
#

Based on the code you've shown me, the video doesn't make sense

#

I would expect the squares to move by exactly 1 meter away from their origin point when the vector is normalized

vestal girder
#
    public Transform avoidThis;

    private Vector3 origin;


    // Start is called before the first frame update
    void Start()
    {
        origin = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        Avoid();   
    }

    private void Avoid()
    {
        Vector3 direction = avoidThis.position - origin;

        //float dist = direction.magnitude;
        direction.Normalize();

        transform.position = origin + direction;
    }```
#

thats literally all of it

stark oasis
#

and when you move the avoidThis transform around, the squares move in that non-uniform way?

#

where they move further if they're closer

vestal girder
#

when I dont normalize the vector, all of them move the exact same distance in the exact same direction

#

when I do normalize the vector, they all move different directions relative to the object

#

why is this

stark oasis
#

to make this easier to visualize, can you add this to Update?

#

Debug.DrawLine(transform.position, origin);

vestal girder
#

sure 1 sec

stark oasis
#

I think there might be a bit of an illusion going on here

vestal girder
#

blue isnt a good color for this

stark oasis
#

And make sure that the sphere isn't above or below the squares

vestal girder
#

3 dimensionally its moving up, that makes sense, but this is not my problem and not my question

stark oasis
#

It looks like it's below the squares.

vestal girder
#

it is, but again this is not my question and not my problem

stark oasis
#

The vertical offset is making it harder to understand what's happening

#

humor me and line it up vertically

#

it will make things easier to see

vestal girder
#

okay

#

exactly flat y 0 on every

stark oasis
#

oh yeah, and the perspective camera is also going to mess things up a little

#

set the scene view to orthographic and view it from the top

vestal girder
#

if I dont normalize it, why do they all move perfectly in unison?

stark oasis
#

We'll get there.

vestal girder
#

okay

stark oasis
#

look at the normalized version with an ortho camera from above first

vestal girder
#

sure, ortho, top, flat

stark oasis
#

okay, so see how every one of those green lines has the same length?

#

they just point in different directions

vestal girder
#

Right

#

but normalizing has nothing to do with directions? So why is normalizing changing its direction

stark oasis
#

you see a non-uniform grid because each square gets pushed by 1 meter in a different direction

#

exactly 1 meter, always

#

also, is the last column of squares on the right a little bit off?

#

i noticed the gap is smaller in all of these scerenshots

vestal girder
#

yeah I positioned them manually its not a perfect grid

stark oasis
#

notice how all four of these squares have the same gap between them

vestal girder
#

which is unrelated and unimportant but does make it harder to debug I guess

stark oasis
#

they're getting pushed in the same direction, by the same amount

#

so that line doesn't get distorted

vestal girder
#

yes 🤔

stark oasis
#

meanwhile, this line is skewed all over

#

because they're getting pushed in very different directions

#

(again, by exactly 1 meter, always)

vestal girder
#

yes 🤔

#

like here they're all pushed exactly 1 meter away directly away from the position

stark oasis
#

so that's why, when the vector is normalized, you get this sort of varying effect

vestal girder
#

I dont understand why normalizing changes that though

#

because if it wasnt normalized, the orb in this exact position, the entire grid wouldnt be pushed away from that spot

#

the entire grid moves as a giant single object

stark oasis
#

so, switch it back to non-normalized

#

and then show a screenshot with the sphere in the same sort of position

#

put it somewhere so that it's sitting inside of the resulting grid

vestal girder
#

yeah

#

normalized / not normaized

stark oasis
#

so, when not normalized

#

you're moving each square based on how far away the square is

#

the further away the square is, the further it moves

#

imagine this in 1D

vestal girder
#

🤔

stark oasis
#

you have a square at 1, 2, 3, 4, 5, ...

#

and you put the sphere at 0

#

if you normalize the vectors, the squares wind up at 2, 3, 4, 5, 6, ...

#

each one moves to the right by 1

#

if you don't normalize the vectors, the squares wind up at 2, 4, 6, 8, 10, ...

#

each one moves to the right by how far to the right it was

vestal girder
#

I am not getting it at all, I will just describe what I WANT and you tell me why I'm not already getting that 🤔

What I want to do is to push away from that position, but only within a clamped distance relative to how close that position is to the thing.

So like they don't move at all until the position is within X of it, and then they push away from that position, multiplied by the distance

(I know none of my code does any of that yet because I havent gotten there because it wasnt behaving the way I expected)

#

I know to get this I have to multiply by distance at some point

#

I'm starting to get extremely stressed out and go into crisis because I just dont understand and I need to understand and im wasting company time being a fucking stupid idiot who can't solve the most basic vector math

#

how the fuck did I ever get hired when I can barely glue two bricks together 😓

#

but all of this is unrelated

stark oasis
vestal girder
#

visually: I want to push the object in the direction (red) by the magnitude of its distance (gradient)

#

so if its at <distance greater than gradient> it gets pushed zero

#

so to do that the magnitude must be clamped between 1 and 0 over a range of <length>

#

and then pushed in <direction>

#

but... <vector shit I dont understand here>

stark oasis
vestal girder
#

sure

stark oasis
#

so, set it up like i described

#

then enter play mode and turn normalization on and off

stark oasis
#

no, just position it exactly on top of the top-left square

#

leave it in place as you turn normalization on and off

vestal girder
#

oh okay sure

#

the closest one is jank because its moving 1 whole unit away and I cant get it perfectyly on top

stark oasis
#

yeah, it'll be weird

#

normalization cause very violent movements at very short ranges, since a tiny move is a big change in direction

stark oasis
vestal girder
#

Not really?

#

Like, I dont see, I dont understand

#

I am not sure what I am supposed to be seeing and understanding

stark oasis
#

let's say the sphere is at 0

#

and just look at the one column on the left

#

In the left image, the squares are moving based on how far away they are from the sphere

#

if a square is at 4, then it moves by 4

#

if a square is at 0, then it moves by 0

#

In the right image, the squares are moving by 1, always

#

every square moves down by the same distance, because they're always moving by 1

#

this is also why that top-left square goes off at a funky angle

#

it must move by 1

vestal girder
#

but in the not normalized version, they all move by exactly the same distance gap, just larger

#

how is the normalized version any different from not normalized but multiplied down smaller

stark oasis
#

because in the normalized version, each square moves by the same amount

#

in the non-normalized version, they move by different amounts

#

The bottom-left square is moving way further than the top-left

#

You're doubling their positions.

#

It's like scaling up the squares, where the origin is the sphere

vestal girder
#

so Ishould multiply by 0.5?

stark oasis
#

i'm strictly explaining why you're getting the behavior that you're getting

vestal girder
#

Right

stark oasis
#

a numeric example:

#

you have three numbers:

#

1, 2, 3

vestal girder
#

I'm sorry im dumb as shit, you are doing your best and I am just not comprehending

stark oasis
#

how far apart are these numbers?

vestal girder
#

1

#

okay hold on

#

when its not normalized

stark oasis
#

right, and they're evenly spaced

vestal girder
#

why are the values not exponential

#

before normalizing I would expect that each one would get exponentially further away

#

because each one IS further away

stark oasis
#

what do you get?

vestal girder
#

2, 4, 6

stark oasis
#

right.

#

they're still evenly spaced, see?

#

they're just further apart

#

the squares are at 1, 2, and 3

#

the sphere is at 0

#

now, move the sphere to -1

#

and add the distance from the sphere to each of the numbers

#

1 and -1 have a distance of 2

#

so 1 + 2 -> 3

#

2 and -1 have a distance of 3

vestal girder
#

I just don't understand, I am reading the words you are saying but its not forming any kind of comprehension. Its like you are describing color and I am blind andhave never seen color before

stark oasis
#

so 2 + 3 -> 5

#

and 3 and -1 have a distance of 4

#

3 + 4 -> 7

#

we got 3, 5, 7

vestal girder
#

I'm just getting more frustrated because you are trying so hard and I just don't get it, which only makes it harder to comprehend

#

I'm the problem here, I need a break maybe and then will read this when I am not borderline crisis

stark oasis
#

sure. take a break.

vestal girder
#

and maybe it will make sense to me then?

#

lunch, 1 hour 🤔

stark oasis
#

it's good to let new ideas stew for a bit

vestal girder
#

Thank you for your help, I know I am frustratingly thick

stark oasis
#

it's alright

vestal girder
#

ontop of all this I used to be really good at this but its like flowers for algernon, it only makes it worse that I know that I used to know

#

and no longer do

#

(i stopped coding for a few years)

#

and its very much not a fuckin bycycle

#

i no longer recall how to do anything, only things that exist like interfaces and.. like I can't even remember other concepts