TUIOSimulator icon indicating copy to clipboard operation
TUIOSimulator copied to clipboard

Orthographic camera and particles

Open justinLifelike opened this issue 2 years ago • 3 comments

Dear Greg,

I have come across another bottleneck, which is the following:

I have noticed that the simulator only works in orthographic mode and that works fine for me except for the weather I use with Unistorm - The particles are not visible this way. So if I switch the perspective mode I am able to see the weather but then I am not able to move the cars around.

So my question is: Is there a way to make the cars and the application work in perspective mode and if not do you know how I can make the particles work in orthographic mode?

Thanks in advance!

justinLifelike avatar Oct 04 '22 13:10 justinLifelike

hey Justin, you should be able to convert to perspective mode with a little work to confirm that the 2d physics and screen UI are aligned.

Alternatively, if you stay in orthographic mode you could render your 3d scene (particles, etc) to a second camera with a render texture assigned, and then use that render texture in a RawImage component in the UI as a background.

RenderTexture overview: Unity RenderTexture RawImage in UI: Unity UI RawImage

gregharding avatar Oct 04 '22 20:10 gregharding

Awesome! Thanks for the quick response!

I was thinking of trying that so it's great that you are confirming that possibility, I will look into that!

Now let's say I do want to switch to perspective which you say is possible, what do you exactly mean with aligning the 2D physics and screen UI.

Could you give me some hints where to exactly look at or what I would have to change or focus on? Your help is much appreciated, thanks again Greg!

justinLifelike avatar Oct 04 '22 21:10 justinLifelike

In Unity, 2d physics runs in the x/y plane at z=0. You can move 2d bodies in z for organisation but by default the physics doesn't take any notice of it. The screenspace overlay UI is rendered after everything else in the scene and will be drawn over the top of everything and not be affected by any camera position or rotation.

The current setup in the app is to use rays/positions from the screen to check for physics hits for dragging items. This is simplified a bit because the screenspace UI and the physics are aligned. If you change to a perspective camera and don't want to change the hit detection calculations (screen -> 2d physics) then you will probably want to make sure you don't move the camera. If you do move the camera then you'll need to map the screen touches to the camera, and then a ray into the world to find its position at z=0 which is where the 2d physics is based so you can detect hits.

You could also consider using 2 cameras: one for your 3d content which is rendered first, and a second one for the 2d content which is set to not clear the background first so it renders over the top.

gregharding avatar Oct 04 '22 21:10 gregharding