Forum rules - please read before posting.

2D point and click along one axis with held down mouse key

Hi Chris,

I am using the script posted on the wiki (2D point and click along one axis)
It works fine.
But I would like the player moves continuously without always clicking, so I change "SingleClick" to "HeldDown", but the problems raise.

1) If I still hold the key at the player's destination, after the player walks to the destination, the player still moves left and right continuously without stopping. How can I remove the problem. Any suggestion?

2) I make a hotspot and let the player walks to the hotspot marker and turn to the marker direction for interaction. But when I click on the hotspot, the player walks to the hotspot and make turning instead of walking to the hotspot marker. The player still can make turning but stop at the hotspot area (where the mouse click) instead of stopping at the hotspot marker. The above problem won't happen if I change the mouseState to SingleClick. The player can walk and stop at hotspot marker if I click on the hotspot. How can I remove the problem. Any suggestion?

Thanks a lot

AC version 1.69
Unity version 2018.2

Comments

  • 1) Making that single change to the script, I can't get such behaviour myself using the 2D Demo - though it may be to do with your movement accuracy.

    Try tweaking the Settings Manager's Destination accuracy slider, and/or enabling Retro-style movement in the Player's Inspector.

    2) This is likely because the script will do its thing even when the mouse is over a Hotspot, so it's forcing the Player to move to it even when it should be running an Interaction.

    Try replacing the same line with:

    if (KickStarter.playerInput.GetMouseState () == MouseState.HeldDown && KickStarter.playerInteraction.GetActiveHotspot () == null)
    
  • Hi Chris,

    Thanks for your suggestion. Your suggestions all works.
    However, there is one more problem.
    When I press the left/right button on the inventory menu, or drag and drop the inventory to target hotspot, the cursor position makes the player walk to cursor position. Can I also avoid this problem? Any suggestions?

    Thanks a lot.

  • You can also check to see if the mouse is currently over a menu, and if an inventory item is selected. Try this new replacement:

    if (KickStarter.playerInput.GetMouseState () == MouseState.HeldDown &&
        KickStarter.playerInteraction.GetActiveHotspot () == null &&
        !KickStarter.playerMenus.IsMouseOverMenu () &&
        KickStarter.runtimeInventory.SelectedItem != null)
    
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.