Forum rules - please read before posting.

2D character with a 3D background possible?

I'm trying to make an adventure with a 2D character and 3D background (as I have access to easy 2D player creation/animation tools and sketchup for making scenes - graphics are not my strong suit!) - is this possible?

I've been trying to create a 2D character as per the 2D demo, and though I have created a character with a controller and animations, I can't get it to move anywhere around the scene (or animate as if it's moving around the screen). I'm guessing it's because the movement is based on something 3D (a capsule collider perhaps?) but even if I have the 3D thing I'm missing, I'm not sure if I can link a 2D animation to it. 

Any pointers please?

Unity 5.1.0p1 - Adventure Creator 1.45

So 

Comments

  • edited June 2015
    Try to use an empty object or a 3d object as your character that can move and do all the stuff in the 3d projection and make it invisible, then child your 2d character to your 3d character?

    Also go through AC 2d game tutorial video, it's not too long.
  • I'll give that a try SkyTree. I've been through the 2D tutorial multiple times - can't spot anything I've missed though.
  • 2D characters can be used in 3D scenes without problem - the same prefabs in fact can be used for both 2D and 3D scenes.  You can use the 2D Demo game's player prefab, Brain2D, in the 3D Demo scene for example.

    The only change you'd need to make to make a 2D character work perfectly in 3D would be to swap the circle collider by his feet with a Capsule Collider.  But animation and movement should all work regardless.  Post a screenshot of your character's full Inspector, and we'll see what can be done.
  • Hi Chris
    I'm a real Unity newbie so I could've done anything wrong! :D 
    My Character inpector is below.
    The one thing I'm not sure of that I can see is wrong is that I haven't got a "Sprite child". I watched how you attached one in the 2D demo, but my animations can't be dragged to be a child of the character controller. The animation was created in the Unity Animator as per the second screenshot.
    I can click on the frames of my animation in the animator and see them animate (ie. it shows the frame selected) in my scene window, but they appear to be a different type of object to yours (yours was a mini icon showing the first frame of your animation, mine's some type of .anim file). I'm not sure if this something different in Unity 5 to Unity 4, or I'm just doing something wrong.
    image

    image
  • I tried pulling across the Brain2D controller from the examples into the animator controller, that didn't do anything (though my idle graphic changed to an single frame of brain idle, as opposed to my normal single frame of my character at idle). No movement.
    My navmesh instead of turning opaque (as per your 3d demo) has a wireframe when I drag it onto the meshcollider, then disappears when I drag it onto the mesh filter. I've dragged tinpot on to be my default player, and made a collider floor (as per the demo) but there's no tinpot to be seen.
    Gaaaaaah!
    I'm sure there's something fundamentally simple I've missed, I'm just not sure what it is - particularly as I'm not quite sure when to follow the 2D demo and when to follow the 3D. Thoughts???
  • Brain2D's controller is made specifically for the character, so dragging that across won't do anything.

    For 2D characters, you MUST have a sprite child - this is key to getting them to rotate correctly.  However, having the Animator component on the base isn't mandatory - if you need the Animator and Sprite Renderer to be on the same object, you can move both of them onto the sprite child object.

    Apart from how NavMeshes are created (and the need for Sorting Maps in 2D), the general workflow for working in 2D and 3D is largely the same - many of the topics covered in both demos and tutorials are transferrable.

    Where is Tin Pot when the game begins?  He should be positioned at the Default PlayerStart marker, and should be visible if you've put down a floor collider.

    As for the NavMesh, check that you've assigned it as your Default Navmesh in your Scene Manager, and that you created the "NavMesh" layer when installing AC - it's covered by both tutorials.
  • Okay I have a sprite child now. I still have no idea why it's necessary sorry - the manual doesn't really cover it other than to say it holds your character sprite.

    I've now got Tin Pot visible on the scene and doing his idle animation where he's been dropped. 

    The NavMesh is assigned as the default NavMesh and there's a NavMesh layer.

    Neither my player or Tin Pot pay any attention to where the PlayerStart is located - even though its been dragged onto the "Default PlayerStart"

    When I start the game I a hundred messages like these per second on the console

    NullReferenceException: Object reference not set to an instance of an object
    AC.Char.UpdateSpriteChild (Boolean isTopDown, Boolean isUnity2D) (at Assets/AdventureCreator/Scripts/Character/Char.cs:1573)
    AC.Char._Update () (at Assets/AdventureCreator/Scripts/Character/Char.cs:268)
    AC.Player.Update () (at Assets/AdventureCreator/Scripts/Character/Player.cs:69)

    and

    NullReferenceException: Object reference not set to an instance of an object
    AC.PlayerInput.UpdateInput () (at Assets/AdventureCreator/Scripts/Controls/PlayerInput.cs:558)
    AC.StateHandler.Update () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:148)

    Do they help? I appreciate I am a Unity Newbie so sorry if I'm doing something stupid. I appreciate your efforts!

  • I spotted amongst the hundreds of errors one where it was whinging about not finding a main camera. After reorganising the room objects on the scene menu it's substantially better. I've got my character animated and pathfinding - admittedly there's still some wierdness around my animations and pathfinding, but I've got a moving character finally! WOO! Thanks for the help guys!
  • Glad to hear it.  When console errors appear, the first thing to do is always to check the ones at the very top of the window - they'll provide messages from AC itself.
  • edited June 2020

    I know this thread is 5years old but on the off chance - don't suppose anyone knows how to get a shadow from 2d Brain in a 3d scene. Getting 2d Brian working in a 3D scene worked perfectly - just looking around the web for ways of getting shadow and light to work with him (i.e. cast shadow on and from sprite renderer).

    Edit:
    1 step in the right direction...
    https://docs.unity3d.com/Manual/class-SpriteRenderer.html
    The default Material for newly created Sprites is Sprites - Default. Scene lighting does not affect this default Sprite. To have the Sprite react to lighting, assign the Material Default - Diffuse instead. To do this, click the small circle next to the Material field to bring up the object picker window, and select the Default-Diffuse Material.

    But you end up with a box-y quadlike shadow and black square behind the Brain 2d art.

  • Update - it seems the shaders that come with Spine tutorial assets can cast shadows! but not receive shadows - I whish I knew unity a bit better. It feels like I'm a small step away from getting there but...

  • If the shadows are a result of the Spine assets, I'd say Spine's developers are the best people to ask about how receiving shadows might be done.

  • update -after further searching I found a link on this forum, from GreenCubeGames
    https://forum.unity.com/threads/sprites-bumped-diffuse-shader-and-transparent-cutout-bumped-diffuse-with-shadows.217827/

    Which leads to this shader:
    https://github.com/anlev/Unity-2D-Sprite-cast-and-receive-shadows

    Seems to work perfectly, in case anyone else needs it.

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.