Nexus Modding > Scripting
Code improving (check wether a ship is headed towards an object or not)
Arparso:
--- Quote from: Mularac ---If the vectors are perpendicular, the Vdot will be 0, as it would be the cosenus of 90, but you're also forgetting that the scalar product of two vectors is not only the cosenus of those vectors but also the product of the modules of those vectores, so the answer could very well be higher than 1. Or at least that's what I learned in college about this tipe of operation.
--- End quote ---
That's about right, except the part about me forgetting... :P
If you just take the dot product of two vectors, you'd be right, but if you're calculating the dot product of two normalised vectors, you'll just get the cosine of the angle and don't need any further calculation. Now guess, what VNorm() does in my sample script - it normalises the vectors before calculating the dot product ;)
I use that kind of operation quite often when working on shaders and have yet to see it going above 1.
Mularac:
normalized vectors... haven't seen that yet in college. Does it mean that the module (lenght) of those vectors is 1?
Arparso:
Yes. To normalize a vector you just divide every vector component by the length of the vector and you'll get a vector with the same direction, but with a length of 1.
Mularac:
well... it doesn't work, for some reason. E.actualVector is always 0. Apparently, somehow, e.ship:position and e.ship:lastposition represent the same value.
Nevermind... The values of the ship were inverted... m.ac is the ship and m.al is the target, and it was the other way round :P
Navigation
[0] Message Index
[*] Previous page
Go to full version