Forum rules - please read before posting.

How Should i set up 3d Characters in 2d Background

Sorry if my question is answered before,

I am trying to create game like oxenfree in AC with 3d characters and 2d background .

So i needed 2d collider on 3d model and distance the model from the collider  in different z of the background to avoid sorting issue

However when i tried it with tin pot and start the game the model and the collider sticked together again in the same z.

So my question is basically are there any tutorial about how to set up my character whether i should use 2d/3d character in character wizard and how should i set up collider and animation for that.

Comments

  • Welcome to the community, @xyvan.  Thank you for your patience.

    If your game is in 2D, then you can move your background in the Z-axis to prevent it clipping the player.  However, you'll encounter other Z-fighting issues when it comes to e.g. sorting maps and other characters.

    While a 3D character can certainly be used in a 2D scene (by replacing their 3D physics components with 2D ones, as you've done), it does mean that their shader will need to be able to react to changes in their Renderer's Sorting Order value.

    A typical 2D character relies on Sprite Renderers, and the Sorting Order / Order In Layer fields are exposed, and the default Unity sprite shaders will react to changes.  When the scene is set up with a Sorting Map, and a character is given a Follow Sorting Map component, then these fields will be altered dynamically to give them the correct appearance.

    Unfortunately, the other shaders that Unity provides (e.g. the Standard Shader) do not react to changes in the same way.  While the Follow Sorting Map component will change the "Order In Layer" value of a Skinned Mesh Renderer (which exists, but is hidden), it will not have a visible effect with a regular 3D material.

    Therefore, in order to have a 3D character sorted properly in a "true 2D" scene, you'll need to look into getting a shader that can react to this property being changed.  This does fall outside the scope of AC itself, not being a graphics package, but you should be able to find discussions on this topic on the Unity forums.  A couple of examples:


    The other option is to rely on a 3D game, with 3D character, colliders etc, and just keep the camera perspective in 2D.

    Though it won't appear in the list of prefabs in the Scene Manager, the "GameCamera 2D" camera type can still be used in 3D scenes.  To make use of it, just drag it into your scene from /Assets/AdventureCreator/Prefabs/Camera.

    Setting up the 2D background / walkable area etc in 3D will be a little more difficult to achieve, of course.  However, if you rely on Orthographic projection, then enabling 2D mode in the Scene window will give you the same view when editing as when playing the game.
  • ChrisIceBox  Thx very much for your lengthy reply, appreciated 

    I am quite new to programming, so i am trying to understand your 3d approach.

    I am not sure why or how rely on 3d set up will eventually solve z fighting,

    It seems to me even i am adding 3d colliders to the unwalkable area in 2d scene on x,y plane . i wouldnt be able to create a fake sense the depth like 2d will, such as rendering the character place on larger y value at the back of smaller y value  character(like Sorting Map does).Adding collider to entire model will just collide them all or z fighting each other.

    As you mentioned it can be a unity problem not ac, in such case i will just render my 3d model into 2d sprite sheet.

    I apologize if i am asking a dumb question because of my limited programming knowledge.
  • My 3D approach was to rely on a completely 3D scene.  3D colliders won't work in a 2D scene, so the suggestion was to instead place all your 2D sprites in a 3D scene and rely on 3D colliders, NavMeshes, etc.

    Admittedly creating the NavMesh would be somewhat tricky if you rely on Point And Click movement, since it'll need to be elevated at the back so that a "flat" camera can see it.

    That Unity's Standard Shader doesn't react to changes to the "Order In Layer" property isn't so much a bug, but certainly a knowledge of shaders would be necessary to overcome it.

    One other approach I've just thought of is that you could possibly set up a separate camera for each character, and alter the depth of each camera in the same way as you do the "Order In Layer".  I'm not totally sure that would work, but I'll do some investigating and update this thread if I learn any more.

    In the meantime, rendering our models as 2D sprites would certainly do the trick.
  • edited June 2018
    I've written a wiki post on an alternative approach to sorting 3D characters in 2D scenes:


    It's a bit tricky as it requires a separate camera for each character / mid-scene object, but it should mean you can go without custom shaders.  It won't correctly sort multiple characters in the same region, but I'll amend it once the next AC update is out which will allow for that.
  • edited September 2019

    Edit: Silly me, right after posting this I figured it out. I'll leave this here in case anyone else has a similar problem in the future -solution below.

    Original issue:I tried using the script above for sorting layers correctly for 3D character with a 2D background but there's one issue - I need my character to be rendered by an orthographic camera (so we don't get a perspective view of him when he moves to the sides) but I want the sprites in the background to be rendered by a perspective camera (for some effects)

    Issue is, as soon as I apply the script above, it forces my character camera to a become perspective as well, and basically overrides the orthographic setting. Removing the script fixes the issue (but I still need the sorting layers to work of course)

    I don't know how to code, but going through the script I assume it's copying the settings from another camera to the one with the script, which means it's also copying the perspective setting and applying it to this, correct? Any way to avoid this? Thanks!

    Solution: Just remove the line "ownCamera.projectionMatrix = Camera.main.projectionMatrix;" from the code, and it should work perfectly. I'm not sure if this will cause different issues down the line though, but as of now everything seems correct.

    Edit 2: Ran into an issue due to this edit pretty soon lol, but fortunately I've got a solution to that as well.

    Removing the line above will make the objects on your "foreground" layer move at a different speed than your background sprites (so the two layers on either side of your character) giving it an unplanned parallax effect. To avoid this, create a duplicate of the script provided by Chris, and in this do not remove the line above, and add this unedited script only to the foreground camera (and only add the edited script without the line above to the player)

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.