Forum rules - please read before posting.

Move from 2D to 2.5D (i.e. using 3D characters on my 2D scenes)

Dear Chris, long time not hear!
After the success of ENCODYA Demo and Kickstarter (also thanks to your precious help), I'm back to development.

Now, I'd like to change the game mechanic, moving from a 2D to a 2.5D game.
Basically what I want is to keep my 2D scenes, while using 3D characters on them, without starting to design my game and scenes from scratches...
Is there an easy way to just change my 2D player(s) and NPC, to have them in 3D?
(of course I've already the 3D models, animations, etc...)

I've already read your wiki and watched your tutorial, as well as read few forum posts. But I'm not totally sold and sure on what to do, also because some of those links are more than a year old.

What is the best approach for this? Is there an easy way to just change characters from 2D to 3D without re-designing the 2D scenes I have already?

Thank you very much!

Comments

  • 3D characters can move in 2D scenes - the main issue is that of rendering.

    Load up the 2D Demo's Manager/scenes, and drop Tin Pot from the 3D Demo game into the scene. Remove his Rigbody and Capsule Collider, and (optionally) attach a Rigidbody 2D, Circle Collider 2D and check Ignore gravity? in his Inspector.

    You should find that he can then move/turn around the scene as a regular 2D character would - only that he's partically occluded by the background sprites, even with a Follow Sorting Map component.

    This is because Unity's Standard Shader does not respect changes made to a Renderer's "Order In Layer" value in the same way that the Sprite shader does. There are typically two methods to get around this:

    1. Acquire a shader that allows 3D models to have changes made to this value be respected, so that they can be sorted relative to sprites in the scene.
    2. Render each object in the scene with a separate camera, and then change the render order of the cameras - this is what the wiki script you've linked to involves.
  • edited October 2019

    Thanks a lot for your reply Chris! I will give it a try... even if I'm not sure I understood correctly point 1 (the one about shader). Is there any tutorial about that?
    In the meantime I'll try method 2. Thanks!
    One thing though: if I follow your instruction and drop Tin Pot on your Park 2D scene and click play, the Robot falls constantly even if I check "Ignore Gravity?".
    (by the way, I don't see any Capsule Collider nor Rigidbody on its inspector... the only colliders are in the HotspotDetector... I partially solved removing the "Character Controller" but I'm not sure it's the right thing to do...)

  • even if I'm not sure I understood correctly point 1 (the one about shader). Is there any tutorial about that?

    The point is that objects that use the Standard Shader as their material cannot have their sorting order altered in the same way that sprites can - meaning they cannot have their drawing order changed so that they dynamically appear behind objects in front of them, and in front of objects behind them, as they move around the scene.

    This is a general problem with Unity's graphics, not one specific to AC. You should be able to find plenty of resources, however, on the Unity forums.

    I partially solved removing the "Character Controller" but I'm not sure it's the right thing to do...

    What components are on Tin Pot will depend on your Unity version, but the same principle applies. Remove any 3D-based physics components from his prefab to have him work in 2D.

  • Gotcha! Thanks!
    Overall I think would be better for me to start over my scenes and creating them in 2.5D directly... I'll have more control then and no issues, right? (I'll just follow the tutorial and import my 2D background assets there...)

  • edited October 2019

    Ok, so... I've started designing my 2.5D scene and everything works almost good.
    I've however a problem with post-processing.
    Let me explain:
    What I'd love is to control the post-process on my 3D characters only, to better fit into the background (for example applying a heavy anti-alias, a bit of blur, color grading, etc...) All things I can do with Post Process 2.0.
    The problem is that I cannot manage to separate layers and cameras (or, in other words, 3D characters and 2D backgrounds).
    I'm using a GameCamera 2D because I've a scrolling background, as you explained HERE.
    I've tried to put my characters into a new "Characters" layer and I played a bit with duplicating cameras, having one that curls everything but Characters, one that does Characters only (and has the Post-Process), one is set with "Don't clear", and yet I have the post-process in my whole scene (or in none of it).
    I'm not sure if this is Unity related or if it has to do how AC is handling the cameras (depending on Main Camera and such), but I'd love to have the possibility to post-process only my 3D characters without touching the 2D backgrounds!
    I've searched the forum without any luck...
    Any hint?
    Thanks a lot!

  • The AC MainCamera is the only one that does any rendering (by default) - any GameCamera in the scene is disabled at runtime and used merely for reference.

    To have a separate "render" camera that renders only a certain layer, you'd need to parent it to the MainCamera and clear it's transform, so that their positions always match. A simple script could then be used to have it always match the MainCamera's FOV, i.e.:

    void Update ()
    {
        GetComponent <Camera>().fieldOfView = AC.KickStarter.mainCamera.Camera.fieldOfView;
        GetComponent <Camera>().orthographic = AC.KickStarter.mainCamera.Camera.orthographic;
        GetComponent <Camera>().orthographicSize = AC.KickStarter.mainCamera.Camera.orthographicSize;
        GetComponent <Camera>().projectionMatrix = AC.KickStarter.mainCamera.Camera.projectionMatrix;
    }
    
  • Thanks a lot, but I can't make it work...
    Let me explain better my situation.
    I created my project with 2.5D wizard. At the moment I've 4 cameras:
    -MainCamera
    -BackgroundCamera (set by AC by default, I'm not using it)
    -CameraCharacters
    -CameraBackground
    The culling mask of the MainCamera is set to "Everything".
    The CameraBackground and scene were created following this tutorial. Its culling mask is set to "Mixed" (everything but the Characters layer).
    The CameraCharacters was created as you explained above (child of the MainCamera, attached that script, etc.). Its culling mask set to the "Characters" layer.
    I then apply the Post Process Layer and Post Process Volume to the CameraCharacters. Then I play a bit with the "Clear Flags" of the 3 cameras I'm using (MainCamera, CameraBackground, CameraCharacters), but still I cannot make it work.
    I can't isolate the characters from background and I've also noticed some scrolling issues for the camera on which I apply the Post Process.
    Am I doing something wrong?

  • So CameraBackground is a GameCamera 2D?

    Again, this is not rendered at runtime. If you only have need for layering two types of objects (characters and non-characters), then you should leave the MainCamera to render the background. Set its own culling mask to omit Characters, and don't rely on CameraBackground for rendering - you should only have to deal with MainCamera and CameraCharacters.

    The fact that this scene is scrolling adds complexity, because a perspective 2D camera scrolls by changing its projection matrix. Limit testing to a static scene until the rendering issues are sorted.

  • edited October 2019
    Yes, CameraBackground is a GameCamera 2D.
    And ok, I'll give it a try, maybe trying static first.
    However, yesterday I've tried culling out the Characters layer from the Main Camera, but in that way the child camera (Camera Characters) wasn't rendering them either.

    EDIT: I guess my problems were because CameraBackground was set to be active. I'm making progresses now... will let you know. But I'm noticing some "skating" issues, like a problem on the scrolling of the character compared to the scrolling of the background (works perfectly on a static scene now, the issue is just on the different scrolling speed, most probably on the "ease" curve for some reasons.)
  • EDIT2: Another issue is the Matte Shadow material. Very tricky to handle in different camears layers rendering...

  • EDIT 3: I've played a bit and solved the Matte Shadow material issue using a ShadowProjector and adjusting a bit the layers.
    The problem of "skating" unfortunately is still there. Not sure why, but my character is in the wrong position (it moves somehow farther away). I've tried also in Play Mode to switch on/off the "Post Process Layer" component on my CameraCharacters. When it's OFF, my player goes in the correct position (and of course without post-processing), when it's ON the Post Process applies but at the same time moving my character in the wrong position.
    When the Camera is at the center of my location (i.e. starting position), the character position is correct, the farther I move (scrolling) to the left or to the right, the farther my character is going, sliding away.
    If I lock the "horizontal movement" on my GameCamera2D, everything works good (but of course I cannot scroll and move in the other aeras of my location).
    Grrrrr
    Any help is very appreciated!

  • So the issue only occurs when using Post Processing?

    You'll need to explain the issue a little more clearly than "sliding away". Share screenshots if you can, but this may be a Unity issue rather than an AC one.

  • Yes, the issue occurs when Post Processing... plus scrolling.

    I've made a video and some screenshots.

    So I've set a CameraBackground as "Default Camera" in my Scene Manager, it has the GameCamera2D component, but it's inactive: its function is just to scroll the background.

    Then I've my Main Camera rendering everything but Characters. Then its child is CameraCharacters, that render nothing but Characters and it's the one with the Post Processing.

    If I lock "horizontal movement" on the CameraBackground all work good.
    If it's unlocked I've the "sliding" problem (you can notice in the video the exact behavior especially looking at the shadow on the ground... when in center of my location, the shadow is correct, the more I move away, the farther the shadow -therefore character- goes.
    If I switch off Post Processing on my CameraCharacter during PlayMode, the robot goes on its exact position (but I've noticed a minor problem with the reflections on the ground), and going back to the wrong position if I switch on Post Processing.

    Here the video: https://youtu.be/lff7mtEDcEc

    And here the screenshot with my Camera settings: https://pasteboard.co/ICFWgnY.png

    I'm not sure if it's related with Unity, with AC or both! For sure it's related with scrolling and maybe with rendering mode...

  • edited October 2019

    UPDATE:
    I think the issue somehow is in how the script you wrote me (FollowMainCameraFOV) "communicate" with the Post Process.
    I've done the following test cases:
    NO Script | NO Post Process = character is "sliding"
    YES Script | NO Post Process = character is working
    NO Script | YES Post Process = character is "sliding"
    YES Script | YES Post Process = character is "sliding"
    Like that somehow the Post Process kills the effect of the FollowMainCameraFOV script for some reasons...
    Basically the "sliding" effect is like the problem of not having that script attached to my camera.

  • edited October 2019

    The sliding occurs because the character camera is fixed in place, while the MainCamera is scrolling.

    AC scrolls 2D perspective cameras by changing it's internal projection matrix. This allow for a "Ken Burns" effect whereby vanishing points are retained, despite the movement. My guess is that there is a conflict with this technique and Post Processing. I'd be inclined to say that this issue would lie more on the Unity side.

    You can confirm this by temporarily switching all cameras to use Orthographic projection. Does the sliding effect then cease?

    It may be possible to instead have the character camera rely on the "Physical Camera" settings instead. I shall do some investigation and let you know if I come up with anything.

  • If I set all the cameras (including the BackgroundCamera, the one with GameCamera2D script attached) to ortographic, my characters disappear for some reasons... If I set MainCamera and CameraCharacters to ortographic and BackgroundCamera left to perspective, I still have the sliding problem.
    I've tried googling around "Post Process" and "Projection Matrix", and I've found a thread on the official PostProcess GitHub, HERE.
    Maybe the solution is in there somewhere?

  • It's a bug with PostProcessing, then. The thread does offer a few suggestions, in particular that made by manutoo on 5 Sep.

    I wonder if this also occurs if when affecting the Lens Shift value of a physical camera. As another test, try disabling the custom script (so that the camera is not linked to AC), enable "Physical Camera" and play with the Lens Shift at runtime - is that able to move with PostProcessing? If so, it may be possible to sync it up with the AC camera.

  • Thanks a lot Chris, as always. I've tried the solution by manutoo, but it's not affecting my case.

    For some reasons I'm unable to play with Lens Shift at runtime...

    I think I might give up and forget the native Post Process and use some third party ones that do more or less the same (I've tried a few and I don't have the "sliding" issue anymore, but I need to combine different ones and tweak a bit here and there to obtain the same than with Post Process V2...)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.