How to snap angles with ExecuteInEditMode?

Hi from Italy!
(I specify my nationality as an excuse for any grammatical errors. If so, correct me without problems. I must improve my English.)

I love the ExecuteInEditMode attribute, and I’m trying to create a tool for a Lara Croft Go-like game.
Besides grid snapping, I also have to rotate my tiles by 90 degrees around their local y-axis.
Here the problem: there is no real match between the angle visualized on the rotation gizmo and the rotation itself. I think that the rotation tool adds\subtracts a delta each frame as long as the mouse button is down, and the method used for positions doesn’t work 'cause this tiny delta never exceeds the “RoundToInt” threshold of the snap.

It’s hard to explain, so I make an example.
I create a cube.
I attached a script on this cube that prints its transform.eulerAngles.y each frame.
In the scene, I select the rotate tool and, while pressing CTRL\command, I rotate the cube by any angle.
The script prints 15-15 degrees on the console (the unity default angle snap value), not the angle.

Hope that’s a legitimate question, as it’s not directly material of this lecture.
Or this is the right place to ask.
In case, I apologize. But if you can help, I would really appreciate it.

Thanks.

Hi Luca,

Welcome to our community! :slight_smile:

Unfortunately, I don’t understand your question but that’s not due to your English. Unity internally works with Quaternions, so it is very difficult to tell if your problem stems from the conversion of a Quaternion to an Euler angle without knowing anything specific about your project.

If you rotate the cube, which does not have a parent game object, by 15 degree around the y-axis, the y-rotation value should be 15 in the Inspector.

Also bear in mind that the Transform values of child game object are always relative to their parent’s. If the parent is rotated, the child is rotated as well even though its (local) rotation displays (0, 0, 0).

If this didn’t help you, please feel free to ask our helpful community of students for further advice over on our Discord chat server.

1 Like

This topic was automatically closed after 4 hours. New replies are no longer allowed.

Privacy & Terms