Rotation in 2D for the spinning bomb

Hello! I’m not understanding how rotation exactly works.
In Laser Defender, for the spinning bomb object we’ve used the method transform.Rotate(0, 0, speedOfSpin * Time.deltaTime)

From what I understood the third parameter of the Rotate method is the Z-axis which is from a 3D environment but Laser Defender is 2D, so my question is why is it done like this?

I come from a GameMakerStudio (2d engine) background and I used to do rotation by changing the angle of a sprite.
I’ve noticed there is another method in the Unity documentation (Transform section) which uses angles, I thought we were supposed to use this one.

public void Rotate(Vector3 axis, float angle)

Hi @wes_tiozzom,

Welcome to our community! :slight_smile:

Actually, everything in Unity is 3D. Take a look at the Inspector of your game objects in your “2D” game. You’ll notice that their position consists of three components: x, y, z. This indicates that the game object is in a 3D space.

The z-axis is pointing “into” the screen. That’s why we rotate around that axis.

In many cases, there are multiple ways to make something work in Unity. Rick cannot show all of them because that would make the videos way longer and boring for most students. Nevertheless, please feel to test your ideas. If your code works, it’s a solution by definition. :slight_smile:


See also:

1 Like

Hi @Nina, I was thinking about it and still wasn’t understanding but the answer to this is that we are really rotating the object in 3D through the z-axis even though the game is in “2D”.
I was having problems to visualize this in my head but I’ve found this link that shows what you said about rotating objects.

Thank you very much! :slight_smile:

Thanks a lot for sharing the link! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms