|
Hi, I am trying to make a 2D game in Unity and I am running into this problem of being unable to rotate a 3D object like you would for a 2D object. Here is my problem: I am using a cube to house a material which contains my texture. Now, if you flip a 2D object 180 degrees on the Y axis, you can get it to face the opposite direction. But, this does not happen in Unity. Let's say my character is facing right. Upon rotating him 180 degrees on the Y-axis, he should be facing left. But in Unity, the texture is on a 3D cube and on the other side of that cube, he is upside-down. So, when I rotate him 180 degrees, he ends up facing the correct way, but upside-down. No combination of transform.rotate changes seem to make him face the other way and avoid being upside-down. Is there something I am doing wrong? Perhaps a change in the way the material or the geometry works? Edit: Here is the solution. Thanks for the help. Instead of rendering the texture on the cube, I am now using a plane as suggested. And for the shader, I am using Transparant/Cutout/Soft Edge Unlit.
(comments are locked)
|
|
I guess you could render him on a plane and use a shader that doesn't do back face culling - or you could just set the X scale to minus whatever it is now. -1 for instance. Hi, thanks for the comment. Could you elaborate a bit more on shaders? I know very little about graphics implementation and there are a ton of shaders available as well as the ability to create your own.
May 31 '12 at 07:27 PM
user5200
Yes choosing a shader can be tricky - learning to write them myself at the moment :) Well most shaders won't draw a triangle if it's normal is pointing away from the camera - this makes it more efficient because that face cannot be seen. So if you just use a plane it only has one side so take a normal shader, and look at it from the other side it won't be drawn. So that is probably why you have yours on a cube - of course that gives you texture wrapping issues. It's a single line to turn that off in the shader source - normally the shader will have Cull Back and you just need Cull Off. Then a plane with that shader can draw both sides. I'm guessing for sprites in 2D you are using an unlit transparent shader? Grab the source for it, make a copy, try Cull Off instead of Cull Back wherever it occurs. Buy I would suggest you just negative scale the X - much easier!
May 31 '12 at 07:43 PM
whydoidoit
Except that will probably mean no dynamic batching actually - where multiple things using the same texture are done in a single draw call - that has a challenge I believe when any of the objects are scaled.
May 31 '12 at 07:46 PM
whydoidoit
(comments are locked)
|
