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 a local rotation function to Transform #1788

Closed
AlexanderPruss opened this issue Nov 7, 2020 · 10 comments
Closed

Add a local rotation function to Transform #1788

AlexanderPruss opened this issue Nov 7, 2020 · 10 comments
Milestone

Comments

@AlexanderPruss
Copy link

Describe the project you are working on:

I am working on a 2.5D isometric tactics game.

Describe the problem or limitation you are having in your project:

I wanted to add an input allowing the user to rotate the isometric camera 45 degrees left or right, like you can do in the XCOM series. I naively called Transform.rotate() on the Spatial node holding my camera, expecting the node to rotate in place, i.e. to rotate around Transform.origin. Instead, the node rotated around the global origin.

It was surprising for me that rotate was not a local operation, and that there was a global rotate but no local rotate in Transform.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

Adding a Transform.rotate_local() would make it easier to rotate transforms locally, and make it clear on code-completion which of the rotate functions is local and which isn't.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Two implementations of Transfrom.rotate_local() come to mind.

  1. Multiply the basis by the rotation matrix directly -
    var rotationMatrix = getRotationMatrix(axis, rotationDegrees)
    transform.basis = transform.basis * rotationMatrix

  2. Alternatively, just call the Basis's rotated function.
    transform.basis = transform.basis.rotated(axis, rotationDegrees)

If this enhancement will not be used often, can it be worked around with a few lines of script?:

This enhancement can be worked around by just rotating the basis of the Transform directly. Adding the enhancement would aim chiefly at making the methods of Transform self-document. A newcomer to Godot can't know if Transform.rotate() does a local or a global rotation. But if there's also a Transform.rotate_local() function, then the purpose of both functions becomes immediately clear.

Is there a reason why this should be core and not an add-on in the asset library?:

The purpose of the enhancement is to make the code self-documenting and make it slightly easier to use. This is helpful for everyone, but especially for newer users, who probably don't have add-ons installed.

@AlexanderPruss
Copy link
Author

I think I could put together a PR for this

@AlexanderPruss
Copy link
Author

Well, I went an implemented this only to then discover that there's already a Transform.rotate_basis function that does the exact same thing. So I think we can close this.

@AlexanderPruss
Copy link
Author

Aaand never mind, rotate_basis isn't visible in the editor. I'll open a PR to make it visible.

@AlexanderPruss
Copy link
Author

More comment spam. Transform.rotate_basis actually changes the original Transform rather than returning a new, rotated Transform. So a new function is probably justified.

@twoco
Copy link

twoco commented Jun 2, 2022

In my opinion it's a must have feature. It's very important to be simple able to rotate objects along it's locally axis. We need something like rotation_degrees but local like rotate_object_local. Just the rotate_object_local but with an absolute rotation angle set.

Use case: Rotate the steering wheel of a vehicle. A wheel with rotation of x: 25 in front of the player and should be rotated along it's local y-axis with a absolute angle.

demo

▼ Download Demo Project

Until waiting for this feature. Do you have an idea to implement this with current stuff? I searched for hours and found no solution. I'm exhausted.

@Zireael07
Copy link

For something similar, I just used an additional node above what I wanted to rotate. Worked wonders. But yes, I agree that we need this as a function.

@bluenote10
Copy link

Note that this would be solved by godotengine/godot#55923 which introduces scaled / translated / rotated both in a local and a global variant with consistent semantics as explained in #1336.

@twoco
Copy link

twoco commented Jun 2, 2022

Right, wraping in dummy node like Spatial is a good solution/workaround to reset the rotation for the child and rotate it independently. Thanks. I know that. But somehow I didn't think about it at that moment. 🤦‍♂️ Anyway... we should provide a method for this. I just wonder if we can start with the rotate_object_local method. Or use the same stuff as the Godot editor use when rotating. Or how do other game engines handle this? Not tested, but maybe localRotation in Unity? ...

@Variable-ind
Copy link

Hy 👋, shouldn't this issue be closed now?

@Calinou
Copy link
Member

Calinou commented Oct 24, 2023

Indeed, this was superseded by godotengine/godot#55923. Thanks for checking 🙂

@Calinou Calinou closed this as completed Oct 24, 2023
@Calinou Calinou added this to the 4.0 milestone Oct 24, 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 a pull request may close this issue.

6 participants