Forum rules - please read before posting.

2D sprite in 3D game : NavMesh not fully working

edited February 19 in Technical Q&A

Unity 2022, AI Navigation 2.0

Here's my scenario :
- I have a 3D game with ony the Evil Lair assets.
- I want the characters to be 2D (billboard)

My steps to achieve it were surprisingly easy :
- Add an empty node to the scene, call it "Player".
- Add a Player component to it
- Add a Capsule collider to it (weirdly enough, the player doesn't fall through the floor without it)
- Import the "2D sprite" package into the 3D game* to get access to 2D sprites.
- Add a 2D sprite child to the Player node. Drop an actual sprite asset into its "Sprite" slot. Note: I make that node a child of the Player to be able to adjust its X and Y offsets relative to the player node. Nothing fancy
- Finally, drop that sprite node into the "sprite child" property of the Player node.
- Oh, and change "Rotate sprite to" to "Full camera rotation". Instant billboard. Nice!

Run the game :

  • The player can walk around and is a billboard. Success!
  • The player cannot go through the built-in obstacles of the "Evil Lair" scene, such as the torture table. Success!

PROBLEM:
- The player can pass through my own added obstacles (I added a white cube to the scene with a box collider). FAIL!

Note that unlike my sprite Tinpot just works. It gets blocked by my obstacles without problems. I added a NavMesh (see below) out of desperation.

Why can the player pass through my own obstacles when it's properly blocked by the default obstacles of the Evil Lair?

Troubleshooting :
- I thought I'd rebake the NavMesh but I can't find it?
- I added my own NavMesh and baked it. It seems to be baked properly, but the player still goes through my own added obstacle (cube with collider)
- I tried adding a Rigid Body to the Player node but now it fails to walk around properly, it's stuck along the Z axis. I don't understand why. Do I actually need a Rigid Body? (it brings me back to the question : why does the player not fall through the floor?)

  • FYI, if you wondered why I use 2D sprite instead of the Square 3D primitive: 3D square was no good as the blue arrow is pointing _downwards by default in those, instead of pointing away from the surface. The blue arrow is the one that Unity considers to be "forward" so it would mess with the billboard)_

Comments

  • How are you intending to move your Player character? Through Point and Click, or Direct?

    Try replacing the Rigidbody + Capsule Collider pairing with a Character Controller of similar size.

  • Also: make sure the Player's Turn root object in 3D? option is checked - this is necessary for 2D characters in 3D scenes.

  • Yes, I want a Point n Click system.

    It seems to work now, with a Character Controller. Is there a resource explaining wy 3D primer's tinpot needs a rigid body + collider whereas we need a character controller here?

    Follow-up: I'm not sure if enabling "Turn root object in 3D" made anything better but I'll trust you with that, at least it didn't break anything.

    The last annoying thing is that the character behaves more like a 3D character than a 2D character.
    ~~
    By that, I mean that it seems to be "magnetized" and pulled by important locations of waypoints. One of the side effects is that his speed increases when he gets close to what I'm guessing is a waypoint computed by the navigation system. It looks disgraceful.

    Also he manages to climb onto things (with the same "pulled" acceleration effect) even when the passage up is quite narrow (e.g. he can climb onto a table when walking close to its corners) but then he can't walk down.~~

    EDIT: A big part of the awkwardness seems to be resolved when I deleted the NavMesh, created a new one and rebaked it. Maybe it had bad settings, I don't know.

    It remains that every tip meant to make the character behave as predictably as possible (like in a 2D game) is welcome : constant speed, straight movement lines, etc. I don't want the character to look more like he's controlled by a physics engine than simply being strictly snapped onto the floor.

  • High acceleration and deceleration values will make speed appear more constant.

    However, AC has a Retro-style movement option that's intended to give 2D characters a more classic feel, with linear movement and rotation. Though it's intended for fully-2D games, it should work in 3D as well.

    This movement takes complete control over a character's positioning, though - so it's not compatible with Unity's physics component. For it to work correctly, you'll need to remove the Capsule Collider (or Rigidbody+Collider, if present). For a point-and-click game, however, these are often not necessary.

  • OK I'll try. I no longer have any collider as I've used the "Character controller" as you suggested.

  • There's a thing I didn't understand.

    You wrote:
    "
    _AC has a Retro-style movement option (...) Though it's intended for fully-2D games, it should work in 3D as well.

    This movement (...) is not compatible with Unity's physics component. For it to work correctly, you'll need to remove the Capsule Collider (or Rigidbody+Collider, if present).
    "

    But in another thread you wrote that the retro-style movement is NOT compatible either with "character controller".
    I thought that the two alternatives were A) collider+rigid Body, OR B) character controller. And that only the latter was compatible with retro-style movement
    But now it seems that NEITHER of them is compatible with retro-style movement.
    Any insight on this? If I can't use "retro-style movement" then do I simply crank up the acceleration and call it a day?
  • Character Controller is a type of Unity physics component - retro mode pathfinding will not work with that either. Remove all such components (Rigidbody, Collider, Character Controller) if you intend to use it.

    If I can't use "retro-style movement" then do I simply crank up the acceleration and call it a day?

    As I said, retro-mode is intended for 2D games - in 3D, you'll miss out on 3D physics aspects such as gravity etc. It may be enough, but replacing it with high acceleration values may be what's needed - it all depends on your specific project's needs. The best way to know is to just try both and see what feels best.

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.