Forum rules - please read before posting.

Point & Click Movement (Unity2D + Polygon Collider)

Hey everyone,

I'm having a problem with the Point & Click movement using Unity2D in the camera settings and the polygon collider as pathfinding method.

My problem: Whenever I click outside the NavMesh, the algorithm looks for the point on the mesh that is nearest to my click and sends the character there. Depending on the mesh, this might be okay, but if there actually is a point straight underneath the click, it would just feel better, if the character would move right there. I checked modern 2D adventure games, and almost every game works this way. 

image

In the picture above, the white cross is the point where I click. The pathfinding algorithm then computes the point marked in blue as nearest point to the interaction and sends my character right there. However, I would like the character to move to the yellow point.

My questions:
What do you think? Is this behavior desirable? Would you expect the character to move to the blue or the yellow point? I found it very awkward, within this navmesh the character makes very little steps when you want him to move somewhere on the right side, because he is always getting caught at the edges of the navmesh. 
Would be okay if there ways no way where he could go underneath the click though. And, as I'm assuming right now, only then.

But then... no one ever has had problem with this. Am I missing something? Am I doing something wrong? Would using a different pathfinding / camera setting solve my problem?

And finally, technically: I would probably edit the NavigationEngine_PolygonCollider class, specifically the GetPointsArray(...) method. There, at the very beginning, check if there is a NavMesh point straight underneath the interaction point, and if so, move the target right there. If not, just continue. Good idea? Different approaches?

Thanks for everyone's feedback!
Marcus

Comments

  • I can see what your saying.

    For me, i usually click the place where i want the character to move to anyway, so that would be on the navmesh.

    You can change the movemnt so it only works when clicking on the navmesh.

    Maybe this is something more of what you want?
  • No, I was really going for the way I described it. Anyway, I understood a few things wrong first, and the right place in the code is in PlayerMovement.cs within PointControlPlayer(). 

    Right before the point, where the point nearest to the mesh is actually being searched (for loop with RaycastNavMesh(...) calls inside) I inserted a search for a point right underneath the click and only go for the original search if no point straight underneath the interaction point is found. Works like a charm! 

    bool pointUnderneath = false;
    for (int i=1; i<Screen.height * KickStarter.settingsManager.walkableClickRange; i+=4)
    {
    if (RaycastNavMesh (new Vector2 (simulatedMouse.x, simulatedMouse.y - i), doubleClick))
    {
    pointUnderneath = true;
    break;
    }
    }
    if (!pointUnderneath)
    {
    for (int i=1; i<Screen.height * KickStarter.settingsManager.walkableClickRange; i+=4)
    {
    // Up
    ...
    }
    }

    I really like the feel of the navigation now.

    @ChrisIceBox Maybe having more settings considering how this works could be something for a future update?


  • Would be nice to be able to customize this for each scene individually.
  • I think per-scene options would probably be overkill, personally - it's always a balancing act between giving enough control vs streamlining as much as possible.  But your point about prioritising directly underneath the cursor first is a good one, and I'll consider it in an update.
  • I completely agree with the original post. Would make a great feature! :)
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.