Forum rules - please read before posting.

Combine Direct & PointAndClick Movement Methods.

I would like to move my player with Keyboard/Joystick Input but also support "point and click" movement method so that the user may choose whether they want to move with keyboard button or clicking the mouse.

What I've done now is set it to Direct, but I've changed some logic in PlayerMovement.cs so if there is not keyboard input then it will use PointControlPlayer() instead:

if (KickStarter.playerInput.GetMoveKeys() == Vector2.zero) {
    PointControlPlayer();
}
else {
    DirectControlPlayer(false, KickStarter.playerInput.GetMoveKeys());
}

This does not quite work because player will not follow path, only stand in place when clicking with the mouse.

Any tips for combining Direct and PointAndClick methods? I understand a NavMesh and also bounding colliders will be necessary in the scene.

Comments

  • edited December 2017
    You can change the Movement method value in the Settings Manager through script or with the Engine: Manage systems Action.  I'd recommend trying that over modifying AC's scripts, as there are a few other checks for it around the codebase.

    As before, you can get an API reference to the Manager field by right-clicking its label:

    AC.KickStarter.settingsManager.movementMethod

    You should be able to place a custom script in your scene that does this without modifying AC.  That way you can also add things like code to stop the player when switching if need be:

    AC.KickStarter.player.Halt ();
  • Cool, thank you.

    The only script I had to edit was PlayerInput.cs at line 1151 where:
    if (activeArrows == null && KickStarter.settingsManager.movementMethod != MovementMethod.PointAndClick)

    I need this function to still run when PointAndClick is active, so that a horizontal and vertical input is still updated in PointAndClick mode. Just removed the check for that MovementMethod:
    if (activeArrows == null)

    Now, in my own custom script I was able easily switch between PointAndClick and Direct input based on whether or not the player is pressing an input button:

    void Update() {
            if (KickStarter.playerInput.GetMoveKeys() == Vector2.zero) {        
                AC.KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
            }
            else {
                if (AC.KickStarter.settingsManager.movementMethod == MovementMethod.PointAndClick) {
                    AC.KickStarter.player.Halt();
                }
                AC.KickStarter.settingsManager.movementMethod = MovementMethod.Direct;
            }
        }

    I've created a Wiki page about combining movement methods here:
  • edited December 2017
    Yes, I see your point - however, you could try having your custom script check for the raw Unity Input, rather than AC's.  If you're not doing anything special like limiting directions etc, GetMoveKeys() is essentially returning:

    new Vector2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"));

    If that works in place of your use of playerInput.GetMoveKeys(), you should be able to revert the PlayerInput script back to its original.
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.