Repository navigation
Measure get_angle_degrees clockwise from up, like get_angle_radians - #2950
Merged
Merged
Conversation
get_angle_degrees measured clockwise from the right, while get_angle_radians measured clockwise from up, so they disagreed by 90 degrees (#2754). #2157 changed get_angle_degrees and missed get_angle_radians. Both now measure clockwise from up, like Sprite.angle: 0 is up and 90 is right, so a sprite whose image points up faces a point with sprite.angle = get_angle_degrees(...). Examples: - sprite_rotate_around_tank: the corrected barrel passed swapped arguments to get_angle_radians and sat 90 degrees off from the mouse. The default barrel compensation goes from -90 to -180. - turn_and_move: image offset and movement updated for the new angles, so it behaves the same. Its arrival check used <, so a sprite moving straight along an axis never stopped; now <=. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2754:
get_angle_degreesandget_angle_radiansmeasure angles differently.get_angle_degreesbeforeget_angle_radiansbefore (as degrees)Both functions used to measure clockwise from up. #2157 (June 2024) changed
get_angle_degreesto measure clockwise from the right, and missedget_angle_radians.Both now measure clockwise from straight up, like
Sprite.angle: 0 is up and 90 is right. So a sprite whose image points up faces a point withsprite.angle = get_angle_degrees(...), andget_angle_radiansis alwaysmath.radiansof it. Onlyget_angle_degreeschanges, which goes back to its pre-#2157 behavior. The docstrings now say which way the angles go.Breaking: code using
get_angle_degreesgets 90 more than before. The changelog entry is under Unreleased → Breaking Changes, and says to subtract 90 for the old value.The issue proposes
atan2(dy, dx)instead. That's counter-clockwise from the right, so it would have disagreed withSprite.angleby direction.Examples
sprite_rotate_around_tankis the only user ofget_angle_radiansin the repo.correct = True) passed swapped arguments and sat 90° off from the mouse: with the mouse to the right, the barrel lay along the top edge of the tank. It now sticks out toward the mouse.turn_and_move: the image offset and movement math were updated for the new angles.<, so a sprite moving straight along an axis never registered arrival and kept turning. It now uses<=, and every direction stops facing the right way.Tests
New in
tests/unit/test_math.py; there were no tests for these functions before:get_angle_degreesreturns the angle clockwise from up, for six directions.get_angle_radiansmatchesmath.radians(get_angle_degrees(...)).get_angle_degreesfaces its target.12 of the 20 fail on development.
I compared both examples with development by simulation (barrel angle and offset; sprite angle, heading and arrival), and rendered the tank to check the barrel. Full suite: 1799 passed. ruff, mypy and pyright all pass.
🤖 Generated with Claude Code