Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Lekomese · Mar 28, 2019 at 04:04 AM · character movementgetaxisgetkeydown

how can i make my character run and walk ?

Hi, i want to make my character move, like when i hold down "D" button he walk and when i combine it with "Shift" key he start to run. The problem here is I move my character with input.GetAxis, and inside input.getAxis we can customize the buttons like we want to use, i wonder how can I combine the "Shift" key or any key with the key that i add before in the input. getAxis so that can make my character run, and when i release he back to walk.

sorry if my english is bad, i'm beginner with unity.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Saiguru · Mar 28, 2019 at 05:17 AM

Hi @Lekomese

  • For ease of use, you can use the FPS Controller from Characters by importing from Standard Assets.

  • Else you can use a "float runMultiplier" and multiply with the existing speed and if you press Shift just change the "runMultiplier" value so that it runs faster

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by RobAnthem · Mar 28, 2019 at 05:17 AM

For motion like this we normally use a "locomotion" controller, which is usually a blend tree in Animator state machine, you can simply make it so that if vertical input is greater than zero, you set anim move speed to say .5f, and then if you are holding shift, you set it to 1.0f. Then in your blend tree, blend to Run animation if speed is > .5f,, blend to walk if > 0 and < .5f, and if 0 blend to Idle anim. You can also use a matrix in blend tree and add additional parameters for strafing and such. Simply to combine keys though, you can do this.

 void Update()
 {
     float vertical = Input.GetAxis("Vertical");
     if (vertical > 0)
     {
         if (Input.GetKey(KeyCode.LeftShift))
         {
             // running
         }
         else
         {
             //walking
         }
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lekomese · Mar 29, 2019 at 05:06 AM 0
Share

Thank you sir for the answer, but I am still confused by that, I am now making a 2d platformer game and this my script code to make the character walk.

 public CharacterController2D $$anonymous$$ontrol;
 public Float WalkSpeed = 50f;
 float Horizontal2d = 0f;
   
 
  void Update()
     {
 
         Horizontal2d = Input.GetAxisRaw("Horizontal") * WalkSpeed;
 
         Animator2d.SetFloat("Walk", $$anonymous$$athf.Abs(Horizontal2d));
      }
 
  Void FIxedUpdate()
    {        
        $$anonymous$$ontrol.$$anonymous$$ove(Horizontal2d* Time.fixedDeltaTime, false, false);
         
     }


Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input getkey, keyup and keydown not working?! 1 Answer

is possible mouse wheel key in else than GetAxis? 2 Answers

moving a character a fixed amount help please 3 Answers

'if' check inside an OnTriggerStay is called numerous times although it shouldn't? (DRIVING ME INSANE) 1 Answer

How to rotate object x degrees on 1 key press with lerpangle 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges