Forum rules - please read before posting.

How can i remember mouse position when click on navmesh 2d

I would like to have my player move through a Gap, the approach i am thinking now is
1.Save the mouseclick position
2. Stop player movement on one side of the Gap enter trigger zone
3. Play a animation that the player jump over the Gap
4. continue the movement to the saved mouseclick position.

So my question is are there a way to save the Last mouse position when click on navmesh?
or there is any approach?

Comments

  • Using Raycasting, A custom script can be used to record the mouse position when clicking over a NavMesh, e.g.:

    Vector2 lastClickNavPosition;
    void Update ()
    {
        if (Input.GetMouseButtonDown (0))
        {
            RaycastHit2D hit = UnityVersionHandler.Perform2DRaycast (
                Camera.main.ScreenToWorldPoint (Input.mousePosition),
                Vector2.zero,
                KickStarter.settingsManager.navMeshRaycastLength,
                1 << LayerMask.NameToLayer (KickStarter.settingsManager.navMeshLayer)
                );
    
            if (hit != null)
            {
                lastClickNavPosition = Input.mousePosition;
            }
        }
    }
    

    (Bear in mind this works for a 2D NavMesh with Orthographic camera - you'll have to adapt it for other types).

    This sounds like a very visual problem - I'm not sure how your approach relates to the actual issue. Could you share some screenshots to illustrate exactly what the problem is, and what you're looking to do?

  • edited January 2019

    https://imgur.com/tfOkeYJ
    Something Like this,
    When Character is on 2nd Floor and clicked at NavMesh of 1st Floor

    i would like the character to go to the trigger point to trigger a pre-made animation that will walk the character down the stair

    then the character will carry on his movement to the point player clicked

  • You can create a Trigger logic type at the top of the stairs that uses either the Character: Move to point or Character: Move along path Actions to move him down the stairs.

    A similar Trigger at the bottom of the stairs can make him move up. To prevent him from continually walking up and down the stairs, only one of the Triggers should be active at a time - i.e. when he's at the top of the stairs, only the top Trigger should be enabled.

    Triggers can be enabled and disabled with the Object: Send message Action. This technique is similar to one used in the "Navigating between backgrounds" chapter of the 2.5D tutorial.

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.