- Home /
Rotate a 2D sprite without rotating the transform
Oddly I find a lot of answers for the opposite problem, but in this case I'd like to rotate the 2D sprite without changing the collision.
Answer by TargonStudios · Feb 08, 2015 at 03:32 AM
You want to rotate the sprite, without rotating it's collider? If so, you could just create an empty gameobject, put the collider on it, and make the sprite a child of it. The sprite could rotate all it wants, and the collider would remain on the parent object, not moving.
Answer by unity_VAdh9YNt55SvQA · Dec 04, 2019 at 12:39 PM
@ozcomingfroo_unity In the sprite properties, there is check-box for vertical flip. It flips picture, not game object itself. notice: 180° rotation = vertical filp + horizontal flip
Answer by Rohit-M · Feb 08, 2015 at 03:34 AM
If you'd just like to have the collider not change, you could try:
1) Create an empty game object
2) Add a collider component to the game object (the same collider that you'd use for the sprite)
3) Delete the collider component from the game object that has your sprite
4) Parent the sprite game object to your collider game object (So the sprite is the child)
Now if you rotate the sprite's transform, the collider won't rotate (because it's on a separate object). If you move the collider, the sprite will move with it.
I expected there to be a simpler way, considering this seems to happen on accident to some. It might just be my bad guess, but isn't using multiple game objects somewhat inefficient?
The very fact that you're using sprites makes me assume the game is 2-D. So you're probably not going to have to worry about being "inefficient" (depending on what you're doing). Even if so, an empty game object will do little to nothing.
I don't think you can ever optimize too much. If an empty Game Object is really that impact-less, I might consider it, but I'm just surprised I haven't heard a different method.
Honestly, it seems like making the script(Or what ever it is) to keep the collider from rotating, while allowing the texture to rotate would take more work (plus being less efficient) than to just add a parent. It's probably the best choice.
Answer by ozcomingfroo_unity · May 24, 2019 at 12:28 PM
The answer was already given but I'll give my own anyway. I searched for this issue and the answer was not what I was exactly looking for ,I.E. in my case anyway.
I currently build a classic space-shooter and I made some enemy space ship sprites. The the sprites have the enemy looking "up" which is the opposite direction of the player that is position at the bottom.
Since I only need to change rotation of the sprite itself, I thought maybe Unity had the tools to do some basic editing to the sprites such as rotating the image itself and replace the old with the new. No such feature was found in my case, which is why I resorted to use a simple image editor.
Answer by unity_VAdh9YNt55SvQA · Dec 05, 2019 at 09:57 AM
@ozcomingfroo_unity In the sprite properties, there is check-box for vertical flip. It flips picture, not game object itself. notice: 180° rotation = vertical filp + horizontal flip
,is not there check-box for vertical flip in sprite properties ? I have not editor juset here, but i im sure, this option was there.
Your answer
Follow this Question
Related Questions
[2D] How do you rotate a 2D sprite left and right with C#? 2 Answers
Finding the centre of two touches 2 Answers
Quaternion Rotate Towards Y Value 1 Answer
Sprite "face" second sprite only on Z axis 2 Answers
2D lock x,y rotation to look at target 2 Answers