x


2D rotation along the Y-axis produces undesirable results

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.

more ▼

asked May 31 '12 at 12:25 AM

user5200 gravatar image

user5200
88 10 17 18

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 31 '12 at 12:28 AM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 101

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)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2171
x38
x6
x4

asked: May 31 '12 at 12:25 AM

Seen: 738 times

Last Updated: Jun 01 '12 at 11:35 PM