Unity Community


Results 1 to 4 of 4

  1. Location
    British Columbia, Canada
    Posts
    332

    Input.GetButtonDown not working...

    Howdy Unityers,

    Been fiddling around with Unity and have encountered a curious problem. Input.GetButtonDown() doesn't seem to always register...and I can't find any reason at all for it.

    When I put this code into a FixedUpdate()

    Code:  
    1.     function FixedUpdate () {
    2.     if (Input.GetButtonDown("Fire1"))
    3.     {
    4.             Debug.Log(Time.time);
    5.             //Jump();
    6.     }
    7. }

    Each time I click it should update the time in my debugger, right? Well, sometimes it just misses it. Fire1 is mapped to either the left mouse or the ctrl key, and this problem happens if I use the ctrl key or the mouse button. Sometimes when I click, it just doesn't register at all...no other variables or conditions at all. You can copy this code, apply it to an object and click away to see the problem. Is this a known bug? I was searching around and didn't seem to find anything...

    Thanks for any help!

  2. Volunteer Moderator
    Posts
    23,731

    Re: Input.GetButtonDown not working...

    It's not a bug. You can't really use GetButtonDown in FixedUpdate, because it's only true for the one frame in which it occurs, and it's reasonably likely (depending on the framerate vs. the physics framerate) that FixedUpdate won't be executed during that particular frame.

    --Eric
    SpriteTile: new tile system that works seamlessly with Unity 4.3 sprites
    FlyingText3D: dynamic 3D text with TTF fonts | Vectrosity: fast & easy line drawing
    Nifty utilities! Stitch terrains together - runtime model importing - file browser - fractal landscapes


  3. Location
    British Columbia, Canada
    Posts
    332
    Oh. Good to know it's not a bug.

    After reading your response, I went out and learned about the differences between Update and FixedUpdate...so basically if I'm performing any kind of physics (like CharacterController.Move or AddForce) I should use FixedUpdate, but for anything else I use Update?

    Thanks for the quick response...and just looked at your post count...and it's over 9000! You are one helpful guy Eric, seriously, half my questions I ask are answered by you!

  4. Volunteer Moderator
    Posts
    23,731
    Quote Originally Posted by IronWarrior
    so basically if I'm performing any kind of physics (like CharacterController.Move or AddForce) I should use FixedUpdate, but for anything else I use Update?
    Yep. Unfortunately somebody already beat you to the "over 9000" thing in another topic.

    --Eric
    SpriteTile: new tile system that works seamlessly with Unity 4.3 sprites
    FlyingText3D: dynamic 3D text with TTF fonts | Vectrosity: fast & easy line drawing
    Nifty utilities! Stitch terrains together - runtime model importing - file browser - fractal landscapes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •