FANDOM


In my game, I want 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.

You can change the Movement method value in the Settings Manager through script or with the Engine: Manage systems Action. You can get an API reference to the Manager field by right-clicking its label: AC.KickStarter.settingsManager.movementMethod

We will use a custom script but will need to modify 1 AC script first before it will work. Open PlayerInput.cs and go to the function UpdateDirectInput() at line 1151:

if (activeArrows == null && KickStarter.settingsManager.movementMethod != MovementMethod.PointAndClick)

We need this function to continue, even when the MovementMethod is PointAndClick, so modify this line so it only check for activeArrows:

if (activeArrows == null)

Now, in your own custom script and in the Update() function, you can toggle between PointAndClick and Direct based on whether or not the player is pressing a movement 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;
        }
    }

    That's it! Now your can easily choose how to move your character at runtime, either by clicking with the mouse or pressing keyboard buttons.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.