Question about rotation

In lecture 122, we first rotate the sprite 180 degrees in prefab (as seen in 2:56), and then utilize code Euler(0,0,180) to command rotation again. Why do we need to do rotation commands in two parts? I have tried to only use Euler code, but it will not work. The sprite has wrong orientation.

Thanks!

Hi crazymole1,

Welcome to our community! :slight_smile:

First of all, please take a very close look at what Gary does exactly. He rotates a child game object. The child contains the SpriteRenderer. The sprite is just “decoration”.

Then he rotates the root game object via code, not the child. He does that because of the local “forward” axis of the game object. The enemies are supposed to shoot “forward”, no matter how they are rotated. Just like your nose remains in the centre of your face if you turn around, and your nose is always pointing forward from your point of view.

In the case of this game, the “forward” axis should point downwards, so the enemies shoot the player, which is near the bottom of the game screen.

Since the child rotates relative to the parent, the unrotated sprite would point upwards because that’s how it is the case in the original image whose data we use. If we manually rotate it to align it with our “forward” axis, we don’t have to worry about it anymore.

What you see in the video is Gary’s solution. If you have an alternative solution in mind, that’s fine. There are certainly multiple ways to achieve the same outcome in the game.

Did this clear it up for you? :slight_smile:


See also:

1 Like

Privacy & Terms