1
\$\begingroup\$

I have been working with the Third Person Controller of the Standard Assets (called Sample Assets in the beta versions) in Unity 5. When the player press the forward button, the character runs by default, and walks if you hold Left Shift, and I want to swap that.

However, The controller makes use of Blend Trees, and have two scripts to manage movement and input and it's far too complex for me and so I need your help. How can I change the controller so that the player walks by default and has to hold Shift to run?

\$\endgroup\$
0
\$\begingroup\$

The state of the Shift key is checked in the ThirdPersonUserControl.cs script which isn't that difficult.

To just swap the states you most likely (I haven't checked it!) would need to replace the

#if !MOBILE_INPUT
        // walk speed multiplier
        if (Input.GetKey(KeyCode.LeftShift)) m_Move *= 0.5f;
#endif

with

        m_Move *= 0.5f; // Do it before the #if to have your character walk by default on mobile devices too.
#if !MOBILE_INPUT
        // walk speed multiplier
        if (Input.GetKey(KeyCode.LeftShift)) m_Move *= 2;
#endif

or even with just

#if !MOBILE_INPUT
        // walk speed multiplier
        if (!Input.GetKey(KeyCode.LeftShift)) m_Move *= 0.5f;
#endif

if you want the character to run by default on mobile devices.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks Vladimir, that worked! Although I had to change the m_Move multiplier to 0.8f, otherwise the character would walk a couple steps and then freeze in mid-movement. For some reason the walk animation is no longer been played. Instead, character walks with run animation on a slower anim speed, but since my game is FPS, it doens't really matter. \$\endgroup\$ – Odival Quaresma Neto Apr 22 '15 at 18:46
  • \$\begingroup\$ @OdivalQuaresmaNeto Glad I helped you! Not sure why it was necessary for you to change 0.5 to 0.8. I tried now with 0.5 and everything worked like a charm. \$\endgroup\$ – Vladimir Apr 22 '15 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.