Forum rules - please read before posting.

Developing a 2D side-scrolling adventure game

Hello everyone, I am developing a 2D side-scrolling adventure game where the player characters can only move horizontally. I have reviewed all the tutorials, and everything works perfectly except for the scene boundaries. The player character can leave the scene even with the use of NavMesh. Do 2D side-scrolling games require different setups?

Comments

  • Welcome to the community, @Bik.

    What's your game's Movement method currently set to, and what are your AC/Unity versions?

    When using Direct control in a 2D game, there are typically 2 ways to limit where the Player can move.

    The first is to make use of collision - i.e. place down e.g. Box Collider 2D components in the scene to mark out the scene's boundaries. Your Player will need to be equipped with a Rigidbody 2D and 2D Collider of their own to react to these. This is the standard 2D workflow when working in Unity.

    Alternatively, AC has the option to limit the Player's movement to the confines of the active NavMesh. To enable this, just check Auto-stick to NavMesh? at the bottom of the Player's Inspector.

  • Hey Chris,
    Thank you for getting back to me.
    AC version: 1.77.4
    Unity: 2022.3.3f1
    Movement method: Direct

    I have knowledge about how collisions work, and I have already attempted to use them before trying NavMesh. However, the issue remains that the player always goes through the collider, regardless of whether I am using box collision 2D or NavMesh.

    Any thoughts?

  • edited July 2023

    Does the NavMesh encapsulate the colliders?

    If you check Auto-stick to NavMesh?, remove/disable the colliders as they will not be necessary.

    Are any custom scripts involved to prevent vertical movement on the Player?

    As this is a visual problem, any screenshots you can share of the scene and the Player's Inspector will help clarify the issue.

  • Yes, I removed the colliders after I checked "Auto-stick to NavMesh", but still no luck. And no, I'm not using any custom scripts or plugins.

    Here's a screenshot: https://prnt.sc/Mq-TENM_ml3T

    I'm trying to make the Boat on the left block the player from exiting the scene.

  • Is the NavMesh the pentagon at the top?

    The Player will need to be inside the NavMesh for the option to take effect.

  • I attempted to keep the player within the NavMesh, but they still went out the boundaries. Since this is a 2D side-scrolling game, I found Unity box collider 2D to be my preferred option, but unfortunately, that didn't solve the issue either. I'm also getting this yellow error: The HotspotDetector's layer, Default, is the same used by Hotspots, and will prevent Hotspots from being properly detected. It should be moved to the Ignore Raycast layer.

  • You can reduce the number of vertices on the NavMesh to 4, but it will need to be a Polygon Collider component.

    As a test, try this option with the 2D Demo: load up the 2D Demo's Managers + scene from the top toolbar, and then set the Movement method to Direct. At runtime, select the Brain2D Player object in the scene and check the option - you should find that he remains within the NavMesh. Is this the case?

    If so, try dropping the Brain2D Player prefab into your scene - that'll help determine if the problem is with your Player, or the scene.

    I'm also getting this yellow error: The HotspotDetector's layer, Default, is the same used by Hotspots, and will prevent Hotspots from being properly detected. It should be moved to the Ignore Raycast layer.

    Follow its suggestion and move your Player's Hotspot Detector object to the Ignore Raycast layer.

  • Okay, I tried the following:

    1) I used my character in your demo scene, and my character respected your scene boundaries.

    2) I used your character in my scene, but it didn't respect the scene boundaries.

    My current scene setup:
    1) 1 image representing the whole scene (ground, trees, etc). The order in layer is -5
    2) Foreground trees. The order in layer is 20
    3) Player start order in layer is 100
    4) Boat order in layer is 100

    https://prnt.sc/GGaXqnnkeUos

  • Hey Chris,
    I can confirm that the issue has been fixed.
    Regarding the Player's Hotspot Detector. Could you tell me how to move my Player's Hotspot Detector object to the Ignore Raycast layer? Because I couldn't find it.

  • I can confirm that the issue has been fixed.

    For the benefit of any future users with this issue, could you share details of what occured?

    Could you tell me how to move my Player's Hotspot Detector object to the Ignore Raycast layer?

    A GameObject's Layer is assigned at the top of their Inspector:

    https://docs.unity3d.com/2020.1/Documentation/Manual/Layers.html

  • Hey Chris,
    Thank you for your answer.
    Regarding the scene boundaries issue, I changed the Player's rigiddbody from Kinematic to Dynamic and that solved the problem. This was defiantly my fault because I'm new to Unity. :(

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.