I have a sine wave that varies in amplitude. I am trying to make a snowboard game like those old arcade game where if you hold the screen while the slope is going downwards, you gain momentum, but if you hold it while the slope is going upwards, you lose some.
I’m trying to use the dot product of a preset vector ((1, 1).normalized) and the normals of the slope to determine whether or not to accelerate.
Since (1, 1).normalized is diagonal top right, I figured that since 0.5 is my threshold, it’d allow 45 degrees on both sides of the vector, so anything between (0, 1) and (1, 0), exclusively in the first quadrant
float dot = Vector2.Dot(new Vector2(1f, 1f).normalized, normals);
print(normals + " " + dot);
but I’m getting outputs like these in the console
I’m a bit confused. Afaik the dot product will return a value > 0 as long as the tested vector points towards the same hemisphere. Meaning 0.5 and up should cover exclusively the inner half of the hemisphere, no?
edit : here’s an attempt to illustrate my understanding
- In green is my preset vector
- In pink is what I believe would yield a value > 0 when doing the dot product of any vector starting from the origin and the preset vector
- In yellow is what I believe would yield a value > 0.5 when doing the dot product of any vector starting from the origin and the preset vector
For some reason, I am getting dot products > 0.5 a bit further than I believe I should. Purple zone illustrates this.
edit2 - SOLVED : Well I don’t understand this thoroughly so I’ll just say what I actually understand, in a very non methodical way, in case anybody as clueless as me ever reads this. If anybody wants to add more to the topic, please do so
I just found out from this source that you can’t extrapolate what angles are covered linearly. Turns out the threshold for 45 degrees is 0.707, an oddly familiar number
Also turns out I have to go back and fix a bunch of shaders which I never knew were working wrong until today