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 Dunoid · Jan 19, 2016 at 09:24 PM · inputmovement scriptgetaxis

Cannot Jump While Moving Diagonally

I've made a simple movement script for my player (which is just a plain capsule with a rigidbody), and it works well, except I can't jump while holding W and A at the same time. All other combinations (WD, SA, SD, all arrow keys) work fine, but I cannot jump while holding W and A. Here's the movement code:

    void Update() {
         float dt = Time.deltaTime;
         Vector3 movement = 
                new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
         if (movement.magnitude > 1)  //Normalizing movement
             movement = movement / movement.magnitude;
 
         transform.Translate( movement*dt*moveSpeed );
 
         if (IsGrounded() && Input.GetButtonDown("Jump")) {
             //rb is the player's rigidbody
             rb.velocity = new Vector3(rb.velocity.x, jumpStrength, rb.velocity.z);
         }
     }

Edit: My IsGrounded() function shouldn't be affected by diagonal movement, as it just checks if a BoxCollider under the player is overlapping with the ground. Here's all the code involved:

     private bool grounded = true;
     //...
     public bool IsGrounded() {
          return grounded;
     }
     void OnTriggerEnter() {
         grounded = true;
     }
     void OnTriggerStay() {
         grounded = true;
     }
     void OnTriggerExit() {
         grounded = false;
     }

Setting grounded to public shows it works correctly, and I can jump properly going any other diagonal direction (and all directions when using the arrow keys). Literally the only scenario where I can't jump is when I'm holding both the W and A keys.

Comment
Add comment · Show 4
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 ShadyProductions · Jan 19, 2016 at 09:34 PM 0
Share

is your IsGrounded() method maybe affected by moving diagonally?

avatar image brunocoimbra · Jan 19, 2016 at 11:13 PM 0
Share

Use "Debug.Log(IsGrounded());" before the last if statement, and check if it is true while using W and A. If so, post your IsGrounded() code so we can help you.

avatar image NoseKills · Jan 20, 2016 at 07:16 AM 0
Share

Have you tried if all the key events are triggered? $$anonymous$$aybe it's just a ghosting problem

avatar image incorrect · Jan 20, 2016 at 08:59 AM 0
Share
  1. Never do any physics in Update(). Use FixedUpdate() ins$$anonymous$$d

  2. Never do any transform manipulations with objects that have Rigidbody attached to them unless you understand what's the difference. Use Rigidbody.position, for example. In FixedUpdate(), of course.

I bet, if you will fix this, your problem can be solved. Try ins$$anonymous$$d of doing transform.Translate use something like

 rigidbody.velocity = maxVelocity * inputVector;

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Kali2048 · Jan 20, 2016 at 07:30 AM

It may be your keyboard hardware problem, see this very similar problem : http://answers.unity3d.com/questions/162207/why-cant-i-firing-a-bullet-when-holding-down-left.html

Comment
Add comment · Show 4 · 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 Khozo · Jan 20, 2016 at 09:56 AM 0
Share

It's possible, some keyboards only allow a limited amount of inputs at any one time (2-3). And I don't see anything wrong with his script.

avatar image brunocoimbra Khozo · Jan 20, 2016 at 03:23 PM 0
Share

If it was the inputs amount limitation, it will have problems with any diagonal movement + jump...

avatar image NoseKills brunocoimbra · Jan 20, 2016 at 05:22 PM 0
Share

If it was the inputs amount limitation, it will have problems with any diagonal movement + jump...

True, but it's not a limitation of x amount of simultaneous key presses. Ghosting can happen on different key combinations depending on the hardware. Some combo of 4 keys might work totally fine while some combo of 3 does not.

Like I said in my earlier comment, it should be easy to detect though so we can rule this possibility out or confirm it... OP should just put some Debug.Log in Input.Get$$anonymous$$ey or Get$$anonymous$$eyDown to see if the presses trigger at all.

avatar image Dunoid · Jan 20, 2016 at 08:39 PM 0
Share

I opened Notepad++ and confirmed the problem is my keyboard. I'll just use a controller, I guess.

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

8 People are following this question.

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

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Input.GetAxis returning nonsensical values for HID Sensor/GameController 0 Answers

[SOLVED] Input.GetAxis("Horizontal") returns wrong value? -1 Answers

How to get ScrollWheel values using a laptop touchpad? 1 Answer

Get axis literal keyboard or mouse value... not possible? 0 Answers


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