Forum rules - please read before posting.

Enhanced Point and Click Method

edited October 2023 in Technical Q&A

Hello, I'm finalizing my new game Soul Tolerance (you can try a demo HERE), and I'd like to enhance a bit how the point and click movement method works.
Since my game has a rather wide camera and lot of walking/running around (as you can see if trying the demo), I wish to enhance user's experience by having a "refresh of mouse click on holding down the button".

Now, I thought that "Straight To Cursor" (plus ticking "single click moves the player" and also "double click for run") was doing exactly that, but it doesn't work (if I set "straight-to-cursor" plus those two options, it basically behaves exactly like point and click... holding down the left mouse button does nothing. I've tried to change pathfinding update to 0 and to 0.1, same result).

So either my straight-to-cursor is not working for some weird reasons, or it is not the right approach.

I'll try to explain myself better.
Now, if I want to run to a point, I double click to that point on my ground (navmesh), but if I want to run for a lot (i.e. to a point way out of the camera view), I'm forced to double-click, wait to reach a point, double-click again, wait, and so on... which is basically spamming often the left mouse button and that can be frustrating. (something similar happens also in Three Minutes To Eight, released last Monday, especially on the long side-scrolling street scene... By the way, Chris, feel free to include it in the "Made with AC" games).

So my idea is the following:

  • if the player HOLDS the left mouse button on a point and click method after clicking the destination, there's a refresh "click" after a certain amount of time (which can be customized via slider), for example 0.2s.
  • this should work both if the user single clicked (therefore a single click + hold, will make the player walk to the point the mouse is over, recalculating the path every float seconds), and if double clicked (therefore a double click + hold on the second click, will make the player run and keep running at the refresh rate to the next point).
  • at that refresh rate, my Click Marker should move to the new position, to show the user where the player is going.
  • I don't want to rely on the "Run threshold" of straight-to-cursor (but only on the double click).

I wonder if there is already something like this integrated with AC (i.e. the Straight To Cursor? But then why is not working on my end?), or if someone ever tried this before with AC (I've found THIS on the forum, but it mentions again the straight to cursor, and I can't reproduce).

I've read the Manual about straight-to-cursor, but I'm probably missing something... Could it be that some UI is blocking my "movement to cursor" as if the camera + mouse position is somehow not working? Some missing raycast? Where could I investigate something like that?

P.S.
Unity 2021.1.3
AC 1.76.1

P.P.S.
A screenshot with the Movement Settings can be found HERE.

P.P.P.S.
I tested the straight-to-cursor method on "Three Minutes To Eight" and it works as intended, I'll include it with the next patch. Not sure why I cannot make it work in "Soul Tolerance"...

Comments

  • UPDATE:
    I've found where the problem was...
    In the "Game Engine / Player Input" I had for some reasons "Mouse Mid Button" as "Drag Override Input"... (maybe for something related with camera spinning?) So basically the "straight-to-cursor" was assigned to it!!! DANG!!!

    I'm leaving this post in case someone else has a similar issue.

    Now it almost works as intended... From my "bullet-points-wishlist" above, just this point is missing:

    • at that refresh rate, my Click Marker should move to the new position, to show the user where the player is going.

    Meaning: everything works great, but my Click Marker Prefab is not "updating" to the new path. It's a prefab with a glowing ring, which disappears when the player stops. The problem is if I click on a point, then hold and drag my player to another direction, that click marker prefab keeps glowing on a totally different point, and disappears only when I stop running. How can I "teleport" it to the new pathfinding destination?

  • The Click Marker prefab will spawn on the first click. For holding the mouse down, a custom script may be necessary.

    What are your current "Movement settings" properties in the Settings Manager?

  • I shared the Movement Settings at the end of my first post.

    One more thing... I noticed that I cannot return to "walk" if I drag the mouse away from player (it starts to run) and then going back closer to it (it still runs).

  • edited October 2023

    And a couple more things which are not tuned perfectly...

    • Apparently if I hold to run around, and move the cursor over a hotspot, then keep holding and running, when my character stops, it launches the previously "hovered" hotspot interaction.
    • Now dragging and running around doesn't work perfectly with triggers... I can do a Character/MovingAlongPath/StopPathfinding but it if keep holding the button, eventually my character will keep running, having a weird behavior. How can somehow force a "release the button" via trigger/action, even if the user is holding it? (i.e. holding should stop working until the next click)

    And regarding the "walk/run" drag of my previous message, I think the issue is related with my camera angle and camera distance from player... For example, if the camera is behind and I move the mouse a bit farther, it works, but if I move it at the bottom of the screen, it requires more space (due to the perspective and cursor position in space). Is it possible to calculate the drag run threshold based on the "projection screen" of the camera, rather than real world distance? (i.e. 50 pixels on screen away from the player, rather than 20 units away in the real world)

  • (note: the trigger is running in the background, but still would be nice to find a way to interrupt the "hold" left mouse button)

  • One more thing... I noticed that I cannot return to "walk" if I drag the mouse away from player (it starts to run) and then going back closer to it (it still runs).

    I was dealing with something similar a while ago:

    https://www.adventurecreator.org/forum/discussion/13545/straight-to-cursor-movement-run-threshold#latest

    I solved it by using the hidden variable Chris added to PlayerMovement, which can be set through custom script.

  • Sorry, it's been too long! The hidden variable was for a different effect. But I'm pretty sure I dealt with the walk-run issue somewhere in the thread above.

  • I will add an option to continue to spawn the Click marker if the Player moves due to the holding-down of the mouse button to pathfind when using Straight To Cursor movement.

    Apparently if I hold to run around, and move the cursor over a hotspot, then keep holding and running, when my character stops, it launches the previously "hovered" hotspot interaction.

    I cannot recreate such behaviour - check that this is still the issue in the latest release (using a backup/duplicate project). If it is, share your full Settings Manager.

    How can somehow force a "release the button" via trigger/action, even if the user is holding it? (i.e. holding should stop working until the next click)

    A custom script can disable Movement when entering a Trigger, until mouse input is no longer detected:

    using UnityEngine;
    using AC;
    
    public class TriggerForceRelease : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnRunTrigger += OnRunTrigger; }
        void OnDisable () { EventManager.OnRunTrigger -= OnRunTrigger; }
    
        void Update ()
        {
            if (!Input.GetMouseButton (0))
            {
                KickStarter.stateHandler.SetMovementSystem (true);
            }
        }
    
        void OnRunTrigger (AC_Trigger trigger, GameObject collidingObject)
        {
            if (collidingObject == KickStarter.player.gameObject)
            {
                KickStarter.stateHandler.SetMovementSystem (false);
                KickStarter.player.EndPath ();
            }
        }
    
    }
    

    Is it possible to calculate the drag run threshold based on the "projection screen" of the camera, rather than real world distance? (i.e. 50 pixels on screen away from the player, rather than 20 units away in the real world)

    Using another custom script, it should be possible to dynamically alter this value at runtime, based on the viewport position difference between the Player and the cursor:

    using UnityEngine;
    using AC;
    
    public class ScreenBasedRunThreshold : MonoBehaviour
    {
    
        public float factor = 1f;
    
        void Update ()
        {
            Vector2 playerPosition = Camera.main.WorldToViewportPoint (KickStarter.player.transform.position);
            Vector2 mousePosition = Camera.main.ScreenToViewportPoint (KickStarter.playerInput.GetMousePosition ());
            float distance = Vector2.Distance (playerPosition, mousePosition);
            KickStarter.settingsManager.dragRunThreshold = distance * factor;
        }
    
    }
    
  • Thanks a lot for all the info! I'll give it a try in the next days!

  • All right, I've made some tests...
    The TriggerForceRelease.cs seems to work.
    The ScreenBasedRunThreshold.cs not really.
    Not sure if I'm doing something wrong or what... But basically if I click and hold, and drag the mouse away from my player, it actually runs, but when I move the mouse again closer to my player, it somehow freaks out... Meaning: it keeps running, until there's some warning about pathfinding method in the consoles. (I've tried different combinations of the "factor", but still...).

    On this screenshot you can have an idea of my game camera point of view.

    I will add an option to continue to spawn the Click marker if the Player moves due to the holding-down of the mouse button to pathfind when using Straight To Cursor movement.

    Waiting for this, I've added this script to my Click Marker prefab and it seems to work... Not the prettiest, but somehow it does the job. What do you think? Any way to make it better?

    public class ClickMarkerRefresher : MonoBehaviour
    {
        //TO BE ATTACHED TO THE CLICK MARKER PREFAB
    
        public float frequencyToUpdateMarker = 1f;
    
        void OnEnable()
        {
            InvokeRepeating("UpdateMarkerPosition", 1f, frequencyToUpdateMarker);
        }
    
        void UpdateMarkerPosition()
        {
            int pathCount = KickStarter.player.GetPath().nodes.Count;
    
            transform.position = KickStarter.player.GetPath().nodes[pathCount - 1];
        }
    }
    
  • Let's try a different approach.

    Before, the threshold was based on the screen distance between the mouse and the Player.

    Instead, let's try having it lerp between a fixed range, based on "how much further above" the cursor is than the Player, in screen-space:

    using UnityEngine;
    using AC;
    
    public class ScreenBasedRunThreshold : MonoBehaviour
    {
    
        public float valueA = 10f;
        public float valueB = 20f;
    
        void Update ()
        {
            Vector2 playerPosition = Camera.main.WorldToViewportPoint (KickStarter.player.transform.position);
            Vector2 mousePosition = Camera.main.ScreenToViewportPoint (KickStarter.playerInput.GetMousePosition ());
    
            float dotProduct = Vector2.Dot ((mousePosition - playerPosition).normalized, Vector2.up);
            float lerpAmount = (dotProduct * 0.5f) + 0.5f;
    
            float newDrag = Mathf.Lerp (valueA, valueB, lerpAmount);
            KickStarter.settingsManager.dragRunThreshold = newDrag;
        }
    
    }
    
  • Ok with this approach the "threshold" works better. However, I still cannot return the player to walk after it started running.
    Meaning: I move my mouse to the Run threshold, my player starts to run, I keep holding down the mouse button and move it around, when I move it back closer to my player, it doesn't slow down, but keeps running. I'd expect that the same mouse distance that made the player run, will return the player to walk.
    Concrete example (numbers are random):

    • I single click and hold. Player is walking.
    • I drag the mouse away from the player.
    • When the mouse is more than 100 pixels away from the player it starts to run.
    • I expect the player to go back to walk if I move the cursor closer to it (i.e. under the 100 pixels threshold).
    • But the result is that the player keeps running.
  • Using the settings from your earlier screenshot, I cannot recreate this behaviour. Did you test this behaviour in the current release in the way mentioned above?

  • The Movement Settings were the same, but I was using a tiny bit older version of AC. Updating AC fixed the issue and it's now working as intended.

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.