Created
May 6, 2020 20:32
-
-
Save Capital-EX/70dc0abbe0575e4c27b3b25013ec8dce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The folloing code correctly tracks the change in | |
angle of the cursor. Factroing in crossing over | |
the boundery between 0 and 2PI. | |
""" | |
# Variable for storing previews positions | |
# Old angle is the original angle Godot | |
# will give. corrected_old_angle is the | |
# angle in the a range [0, 2pi). | |
var old_angle = position.angle_to_point(get_local_mouse_position()) | |
var corrected_old_angle = 0 | |
func _process(delta): | |
# get the angle to the mouse | |
var angle = position.angle_to_point(get_local_mouse_position()) | |
# correct the angle into the range [0, 2pi] | |
var corrected_angle = angle if angle >= 0 else angle + 2*PI | |
# Compute an initial change in angle | |
var da = corrected_angle - corrected_old_angle | |
# check if we've crossed a boundary | |
# readjust the correct angle | |
if old_angle >= 0 and angle < 0: | |
da = corrected_angle - (2 * PI - corrected_old_angle) | |
elif angle >= 0 and old_angle < 0: | |
da = (2 * PI - corrected_old_angle) - corrected_angle | |
# store this for the next computation of da | |
corrected_old_angle = corrected_angle | |
old_angle = angle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment