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

Add rotated_around for Vector2, Vector3 to GDScript and C# #82589

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

profan
Copy link
Contributor

@profan profan commented Sep 30, 2023

Related to: godotengine/godot-proposals#235

Implements helper functions to rotate a vector around a specific origin to Vector2 and Vector3.

Additions

  • Vector2::rotated_around, which rotates a vector around a specific origin, by an angle.
  • Vector3::rotated_around_axis, which rotates a vector around a specific origin given a rotation axis and angle.
  • Vector3::rotated_around, which rotates a vector around a specific origin given a rotation represented as a quaternion.

Implemented for GDScript and C#, includes documentation changes and tests.
I think this change should be compatible with 3.x as well, but I'm not 100%.

... I added this mostly because I wanted it for myself, and I figure others might find it useful :)
(and it also happens to be readily available in eg. Unity)

I was considering adding a rotated_around for Vector3 that takes a Quat as well, so it's more generally useful (and that's the version I'd personally implement on my own projects), but maybe that's a bit much? ... Added it after all, seems useful.

@profan profan requested review from a team as code owners September 30, 2023 17:39
@profan profan changed the title Add rotate_around for Vector2, Vector3 to GDScript and C# Add rotated_around for Vector2, Vector3 to GDScript and C# Sep 30, 2023
@Chaosus Chaosus added this to the 4.2 milestone Sep 30, 2023
@profan profan force-pushed the master branch 2 times, most recently from d99b914 to d278d63 Compare September 30, 2023 19:44
@zinob
Copy link

zinob commented Oct 4, 2023

I like it! This is doable today, but it would be really neat to not have to reinvent the wheel every time I need to rotate something around something.

@YuriSizov YuriSizov modified the milestones: 4.2, 4.x, 4.3 Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants