|
|
|
|
Reply From: |
avencherus |
The dot(Vector2(0, -1)) part: It’s comparing the angle of that normal’s direction between the direction of a vector that is pointing up in a 2D screen coordinate system.
The dot product numbers will tell you if two vectors are:
- Going in the same direction. (Positive number)
- Perpendicular to each other. (0)
- Heading in the opposite direction of each other. (Negative number)
In this example, as others said, they applied an inverse cosine function to convert that number into an angle in radians, then convert it into degrees.
The result is an angle between this normal’s direction and a vector pointing straight up, then comparing if that angle is beyond a threshold.
It’s also very similar to the angle_to()
method inside the vector itself, but it keeps track of a the negative sign. You could use it just the same if you applied absolute value to keep it always positive so it can be compared.
Maybe this is a more readable version for the mind’s eye. (I left the units in radians to cut down on the example):
var up_vector = Vector2(0, -1) # If it's screen coodinates, -1 is up
if(abs(normal.angle_to(up_vector)) < FLOOR_RADIAN_TOLERANCE): #do stuff
https://drive.google.com/file/d/0BxM4Z1C-377uYjBUTDJ6NnJVbmM/view?usp=sharing
the vector is pointing straight up…
thanks for telling about the what the dot product actually does.
I see! Thank you very much for taking the time to explain this!
@Jatz Yeah, it is for screen coordinates, and probably is exactly how it’s being used. I didn’t go looking at the source so I was using the general orientation in math graphing. Makes sense to fix it though.
@Zero You’re welcome, hope it helps.
avencherus | 2016-12-02 14:03