Forum rules - please read before posting.

"Straight To Cursor" movement using navmesh agent integration

Hello! I'm using the navmeshagent integration script and it's working really well for us. Our player sticks to only where the navmesh is, and never falls off or bumps into things. We don't have any dynamic interactions with the player model and other npcs or things in the game during gameplay, so the script is working great as-is.

However, we just got back from Magfest and many of the people that played our game asked for "Straight to cursor" style movement, I think after being popularized by Baldurs Gate 3. I noticed in the manual that AC already includes that movement style but if I set it to that, the player is stuck in place, could that be because it's trying to use the regular AC movement system? Would it be possible to allow the player to choose either straight to cursor or point and click movement style but keep using the navmesh agent integration script?

Thank you for your guidance!

Comments

  • Also! I'm on AC 1.77.4 and Unity 2022.3.6f1 (always forget to give context, sorry!) While doing some testing, forget what I said earlier, if I use a previous player prefab that uses the built-in system she moves again. (But with a lot of the problems that made me switch in the first place, like inconsistent movement speeds and animations and falls of the map in certain spots) But players are also asking for gamepad support so I'm hoping to figure out not only 'straight to cursor' mouse movement, but gamepad movement with this integration: https://adventurecreator.org/scripting-guide/class_a_c_1_1_nav_mesh_agent_integration.html

    It looks like its possible to do controller movement for navmeshagents https://forum.unity.com/threads/navmeshagent-for-player-character-movement-mobile-joystick.226355/ but would the integration script be a good place to implement this functionality?

    And might there be some way to have the integration script respect the straight to cursor functionality switch so that I could give the player a checkbox in the settings for PNC or STC movement styles?

  • edited January 28

    The NavMesh Agent integration requires that the character rely on pathfinding for movement - if they just beeline to the cursor, it won't count.

    Setting a non-zero Pathfind update time (s) value in the Settings Manager should resolve this, as it'll cause all Player movement to rely on pathfinding when using Straight To Cursor movement.

    players are also asking for gamepad support

    AC separates input and movement methods - what control style exactly are you looking for? BG3 on consoles uses movement equivalent to AC's "Direct" movement mode, as opposed to anything cursor-based.

    To provide different options of movement for users, you can change Manager fields at runtime through script - right-click a field's label to get an API reference to it.

    The best way to handle this is to note down all of the different fields that need changing for each option, and then have custom script functions that assign these values. You can then use an Option-linked Global Variable to run the appropriate function when the game begins, or the Variable's value is changed.

    I can elaborate further on this, but we'll first need to know exactly which fields need changing for each option.

  • Wow that worked perfectly, just as you described, thank you!! By setting the pathfind update time, straight to cursor works great. I was also able to get direct movement working too! I just have to set it before playtime.

    For straight to cursor though, I have to start as point and click, then switch during runtime for it to work correctly. I noticed that it disables the 'navmesh agent' component if I start with STC enabled from the start. Or if I start with 'direct' and switch to 'point and click' it also disables the 'navmesh agent' component on my player gameobject. And clicking on the component checkbox doesn't enable it. Is this intended functionality and is there maybe a way to force not disabling that component?

  • Only the NavMesh Agent Integration component should be capable of disabling the NavMesh Agent. As it's standalone (i.e. unreferenced by other scripts), you can duplicate and amend to suit your game's specific needs if necessary.

    However, it's had some improvements in the last few releases. You might want to give the latest AC version a try - in a backup/duplicate project, as it may be that's enough.

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.