Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprite.rotateTo and sprite.rotate issues #307

Closed
quinton-ashley opened this issue Feb 25, 2024 · 2 comments
Closed

sprite.rotateTo and sprite.rotate issues #307

quinton-ashley opened this issue Feb 25, 2024 · 2 comments
Assignees

Comments

@quinton-ashley
Copy link
Owner

quinton-ashley commented Feb 25, 2024

Recently on Discord @ coding398 has pointed out some issues with the sprite.rotateTo and sprite.rotate functions not working as documented. Their behavior is also currently a bit ambiguously defined which is part of the issue.

The sprite.rotateTo function was meant to rotate a sprite to an angle by the shortest angular distance to that angle and at a given rotation speed. However, the problem is that a positive rotation speed can be specified when rotating the shortest angular distance requires a negative rotation speed. Currently this erroneously causes the sprite to rotationally teleport to the destination rotation almost immediately.

Here's an example:

sprite.rotation = 0;

// single line syntax
sprite.rotateTo(200, 2);

// alternative syntax
sprite.rotationSpeed = 2;
sprite.rotateTo(200);

Here's a few ways to solve this:

Option 1. Use the user's rotationSpeed of 2 to rotate the sprite 200 degrees. To rotate the shortest angular distance users would have to do sprite.rotateTo(200, -2); or sprite.rotateTo(-160, -2);. This would be a more straight forward way of doing it and more intuitive just from looking at the code.

Option 2. Adjust the sign of the rotation speed, making it -2, to achieve the shortest angular distance of rotation, which would be -160 degrees. In the documentation the speed param to this function would be labelled an absolute amount of rotation. This is perhaps what most users want to happen in typical use cases, especially when rotating the sprite to face a position, for example sprite.rotateTo(mouse)

Option 3. Do option 1 for rotating to an angle but do option 2 for rotating a sprite to a position.

I'm interested in hearing the community's thoughts on this and how this issue with rotateTo should be fixed.

Additionally, the sprite.rotate function is meant to provide users an easy way to rotate the sprite by an angle at a rotation speed.

There's a similar issue here. How should a rotation of -30 degrees at a speed of -2 be done? Should the angle to rotate by be absolute or should the rotation speed be absolute?

sprite.rotate(-30, 2);
// or
sprite.rotate(30, -2);
// or
sprite.rotate(-30, -2);

I think if either the rotation amount, rotation speed, or both are negative, then the sprite should rotate with a negative rotationSpeed. No wrong answers! I would document it like this though sprite.rotate(-30, -2);

@quinton-ashley
Copy link
Owner Author

quinton-ashley commented Feb 25, 2024

My current thought on this is that rotateTo should just do option 1, as it's just more straightforward and readable. Then perhaps there should be another function rotateMinDistTo or something like that which would implement option 2.

@quinton-ashley
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant