Forum rules - please read before posting.

Player deceleration when changing traveling direction

edited February 2018 in Technical Q&A
Hi Everyone, 

I am new to AC. I want to control a 3rd person player with Direct control.

When the player is controlled to travelling in one direction and then controlled to travel in the opposite direction, the acceleration how to control its deceleration? The acceleration and deceleration parameter under the Movement settings doesn't seem matter at all.

Can I control the player acceleration in the opposition direction when changing travelling direction by 180 degrees? I also want it to "Turn instantly when under player control".

Thanks for your help.

Comments

  • The acceleration and deceleration values are only used when a character transitions between idle and moving states.  Since the character is still moving during the process you're describing, they won't have an effect.

    The built-in movement system isn't designed to have the exact behaviour you're after, but it is possible to have the speed "reset" if the input direction is reversed.  In Char.cs, find the GetNonFacingReductionFactor method, and replace:

    else
    {
        return 1f;
    }


    with:

    else if (IsPlayer && KickStarter.settingsManager.movementMethod == MovementMethod.Direct)
    {
        Vector2 moveDirectionInput = KickStarter.playerInput.GetMoveKeys ();
        Vector3 cameraCorrectedInput = (moveDirectionInput.y * KickStarter.mainCamera.ForwardVector ()) + (moveDirectionInput.x * KickStarter.mainCamera.RightVector ());
        float dotProduct = Vector3.Dot (cameraCorrectedInput, transform.forward);
        return Mathf.Min (1f, dotProduct * dotProduct);
    }
    return 1f;


    Is that closer to the behaviour you're after?  It's certainly possible to make use of another asset or custom motion controller to get the movement you need, but if this change (or some variation of) gets the right result I'll consider adding it as a new option.
  • Thanks for the script! But when I tried it the effect seems to be not very obvious

    As there are also other custom behaviors I may need to implement, I am considering to use a custom motion controller.

    Before I switched to AC, I was using a Character Controller component, and a Character Motor from here:

    But when I set the player Motion Control to "Manual", and attached the Character Controller component to the player (not yet with any scripts to control the component), it flies upward quickly in the y-axis.

    Is there a way to use the Character Controller with AC? Thanks for your help.
  • The Character Controller works with AC by itself - just replace it with your Rigidbody / Capsule Collider, and AC will use that instead automatically.

    AC can work with custom motion controllers, but you must ensure that - as with the Capsule Collider - the Character Controller's bottom is at the root of the object, i.e. a Height value of 2 will result in a Centre Y value of 1.  This was the cause of "flying upward" when I tested the above myself.

    Currently you must also make sure the "Turn instantly when under player control?" option is unchecked, but I'll look into removing this restriction.

    That should allow for you to use the custom controller at all times instead of AC, but custom scripting will be required for a tighter integration - for example, so that control is removed from the player during cutscenes so that you can control him using e.g. the Character: Move to point Action.

    The most simple way to do this, in general terms, is to disable your custom control when not in regular gameplay, and set the Player's Motion Control field to Automatic (and vice-versa when in gameplay).  In the case of the CharacterMotor script, that would be something like:

    if (AC.KickStarter.stateHandler.IsInGameplay ())
    {
        canControl = true;
        AC.KickStarter.player.motionControl = AC.MotionControl.Manual;
    }
    else
    {
        canControl = false;
        AC.KickStarter.player.motionControl = AC.MotionControl.Automatic;
    }


    A more complex method would be to have your custom controller move to the destination that AC sets, which can be done by reading the character script's GetTargetPosition() function.  However, this is more advanced and requires the custom controller to be equipped with the ability to move to target points without user input.

    More on custom motion controllers, along with links to tutorials and script references, can be found in the "Custom motion controllers" chapter of the Manual.
  • edited February 2018
    Thank you for the tips. It works and I can now control the player using the custom scripts.

    But now the player can move when interaction menus are on, even when the "Disable movement when Interaction menus are on?" box is checked. 

    I think I have to set the Motion Control to "Automatic" also when menus are up, right? I tried to use AC.Menu.IsEnabled() but when I used AC.Menu there is no IsEnabled() for me to choose. Or should it be set using the AC.StateHandler?

    Also when I use the InteractionA button at a hotspot, the interaction menu can popup. But when I use the InteractionA or Submit button again in the interaction menu, the interaction is not triggered. Is this issue also related to the Motion Control option? Or something else has to be done?

    I am sorry if these are really basic questions. I am still trying to familiarize myself with the AC class structure and functions..
  • edited February 2018
    No trouble - if it helps you, it'll help others with similar questions.

    Indeed, the script needs to account for interaction menus if you make use of them - custom movement isn't linked to AC's own movement, so the "Disable movement" field won't have an effect.

    AC.Menu is a class name, so you need to get an instance of the class you want in order to access it.  The "Menu scripting" chapter of the Manual covers how to do this:

    AC.Menu myMenu = AC.PlayerMenus.GetMenuWithName ("Interaction");

    However for convenience, the PlayerMenus script has a dedicated method for detecting Interaction menus:

    KickStarter.playerMenus.IsInteractionMenuOn ();


    As for the Interaction input buttons, what is your Interaction Menu's Source field, are you using a cursor or directly-control the menu, and what are your Interface and Interaction settings in the Settings Manager?  There's a lot of choice here that will affect how Interaction menus are triggered.  Probably best to just post screenshots of your Settings Manager and Interaction menu's properties.
  • Thank you so much once again! The player control and movement are finally done and work as I prefer.

    Now I am struggling with the inventory system. But perhaps I should open another post to avoid confusion to other readers.
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.