Zombie conga project

Hi,
I’m reading the zombie conga project on the book, and I’m up to page 66. I got a bit confused with what the book says about velocity vector:

" The length is zombieMovePointsPerSec, the constant you defined earlier as 480 points per second."

In page 67, the book calculates unit vector, followed by multiplying both x and y component by “zombieMovePointsPerSec”. So it is clearly the length != zombieMovePointsPerSec isn’t it ? Have I misinterpreted what the author is trying to say ?
Also, the author Then uses this velocity vector for the “move” function. This function treats the velocity vector as velocity per sec, doesn’t it ? It uses it to calculate “how much to move from original location”. I.e velocity * delta time.

Maybe my confusion is caused by that sentence:

" The length is zombieMovePointsPerSec, the constant you defined earlier as 480 points per second."

could someone share some light? Apology if this is basic question … my vector calculus is very very rusty. Clearly.

Thanks a lot !

Hi @alexwibowo,

What a good question! This is a confusing spot in the reading; it took me some time to understand it myself while I was going through it too.

Correct me if I’m wrong, but I believe your misunderstanding comes from the overlapping use of the word “length”. There are three different lengths discussed under the umbrella term: total length (the original length of the offset vector), a length of 1 (the length of the unit vector), and then zombieMovePointsPerSec (the length the zombie is capable of traveling per second, or the static length of the velocity vector).

Once we’ve normalized the offset vector to obtain the unit vector (the vector’s common denominator), we can then multiply that by 480 points to find the velocity vector, or the distance and direction the zombie will move over the course of one second. Then we pass it into move(sprite:velocity:), which controls how many points the zombie will move in that frame. Multiplying the velocity by delta time gives you yet another vector (the amountToMove), which is then added to the zombie’s current position. The zombie moves that far, and the whole process repeats itself once update(_:) is called again until the zombie finally reaches the location of the user’s tap.

I’m completely new to vector math, so I was learning a bunch while trying to answer your question lol. I hope this helps!

Hi @ajoscelyn,

Thank you very much for your explanation. I guess the piece that confuses me right now is why do we need to multiply the unit vector by 480 points (both the x and y component). You mentioned that this is "to find the velocity vector, or the distance and direction the zombie will move over the course of one second. ". However, I thought we have already established that the zombie will move 480 points per second ? I must have missed something fundamental here…

Thanks again !

@ajoscelyn I think I get it now. Thanks a lot !

Explain to me then… Cause I’m completely lost plzz

The 480 points per second is multiplied by dt, the time delta. So, if 16.7 milliseconds have elapsed, the vector will be 480 points * 16.7 milliseconds (0.0167 seconds) in length, or 8.016 points.

Take the 8.016 points and multiply by 60 FPS (16.7ms refresh rate is ~60FPS), and you get 480.96 points. See how it works?

Hope this helps.