Sign in to follow this  

Unity Input and updating objects

This topic is 2582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

While thinking about the input manager i am creating I began to wonder what the correct way of updating objects based up input was. Currently for any objects that need to be updated I simply add them all to a list of "process objects" and update them. However, with key detection happening at all times, how should I handle updating objects that move depended on input? For example, if I had a camera that moved when I pressed the "W" key, I would want that to process before the next time my list of "process objects" get updated, or is that a bad idea?

Share this post


Link to post
Share on other sites
It shouldn't really matter as long as you do it during the update of the camera. I mean, humans aren't able to distinguish the time between two 60Hz frames, and we aren't able to hold a button down for 1/60th of a second. So it's not going to matter if the user presses the button and you do it immediately, or if you simply wait until the update of the camera and then just check if the player has the button pressed. The user won't be able to tell the difference between the two options.

Share this post


Link to post
Share on other sites
Most of the time, I like to take a "snapshot" of the input state at the start of the frame, and anything checking input goes by that. That way, you can check if a key was just pressed that frame, just released that frame, etc. and it's all consistent for everything. Also more portable, as you can use it on console systems by just checking the state of the keys at the start of the frame, and on event-based input systems like most computers, you have the events update the stored input state, and make a copy of it at the start of the frame.

Just-pressed/just-released events seen by the game are computed logically by examining the current frame's input snapshot versus the previous frame's snapshot, not by setting flags when processing keyup/keydown events or anything. Those are only used to update the current pressed/not pressed states that will be seen next frame. Much easier when the game code can check the up/down states rather than trigger states sometimes, and they all match up.

It doesn't play that well with jumpy frame rates though, like computers do sometimes. You can miss a press and release entirely during a long frame. If it's a problem, you could probably come up with some kind of buffering system, like if a keydown event happens, then make sure the key is seen as being pressed on the next frame regardless of whether it has actually been released before then. But make sure you keep the buffered state separate from the true state, so you don't end up with keys stuck down and such by ignoring the keyup events.

Share this post


Link to post
Share on other sites
Yeah, my previous workplace did something similar, with a global input manager that stored all the button states at the beginning of the frame, but I can't recall ever having a problem with an input or button press being ignored or missed because of a long frame.

Granted, most of the games I worked on were for non-PC platforms (DS, PSP, PS2, Wii), but I would have expected it to be more of a problem on those less powerful platforms. Anyway, DekuTree64 is right that a multiple buffering system would help, but just make sure that you have consistent problems on a retail (not debug) build of the code.

Share this post


Link to post
Share on other sites

This topic is 2582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628645
    • Total Posts
      2984023
  • Similar Content

    • By arash khalaqhdoust
      hey guys i hope you doing all well. last night i released my first game in google app store, i really appreciate you guys  to download it. and share your reviews about it
      the idea of game comes from mini hackgame of Bioshock.
       link of download:
      https://play.google.com/store/apps/details?id=com.RVBinary.piperist
      many thanks
    • By ForgedInteractive
      Who We Are
      We are Forged Interactive, a small team of like-minded game developers with the sole purpose of making games we love! Currently, we're progressing very quickly with our first project and there are plenty of opportunities and work for new interested programmers. With this project, our development platform is Unity 5.5.2 and C# as our behavioral language. Since this project is our first release, the game itself is a smaller project though progress is moving quickly. We are looking to finalize the current project and get started on future projects in the near future and are expanding our team to do so.
       
      Who We Are Looking For:
      Programmer Level Designer  
      About the Game
      Ours is the tale of two siblings, thrown into a world of chaos. Living in the shadow of their parents' heroic deeds and their Uncle's colorful military career, Finn and Atia are about to become the next force to shape our world. How will you rise through the ranks of Hereilla and what will be your legacy? Once defeated your enemies turn coat and join you in your adventures. Players can enjoy a range of troops and abilities based on their gameplay style which become more important as maps introduce more challenging terrain, enemies and bosses. Strong orc knights, dangerous shamans, and even a dragon are out on the prowl. Knowing when to fight and when to run, and how to manage your army is essential. Your actions alone decide the fate of this world.
       
      Previous Work by Team
      Although we are working towards our first game as Forged Interactive, our team members themselves have worked on titles including and not limited to:
      Final Fantasy Kingsglaive FIFA 2017 Xcom 2 Civilization  
      What do we expect?
      Reference work or portfolio. Examples what have you already done and what projects you have worked on academic or otherwise. The ability to commit to the project on a regular basis. If you are going on a two-week trip, we don't mind, but it would be good if you could commit 10+ hours to the project each week. Willingness to work with a royalty based compensation model, you will be paid when the game launches. Openness to learning new tools and techniques
       
      What can we offer?
      Continuous support and availability from our side. You have the ability to give design input, and creative say in the development of the game. Shown in credits on websites, in-game and more. Insight and contacts from within the Industry.
       
      Contact
      If you are interested in knowing more or joining, please email or PM us on Skype. A member of our management team will reply to you within 48 hours.
       
      E-mail: Recruitment@ForgedInteractive.com
      Skype: ForgedInteractive
       
      Regards,
      David, Colin and Joseph
       
      Follow us on:
      Facebook: https://www.facebook.com/ForgedInteractive/
      Twitter: @ForgedInteract
      Youtube: https://www.youtube.com/channel/UCpK3zhq5ToOeDpdI0Eik-Ug?view_as=subscriber
      Reddit: www.reddit.com/user/Forged_Interactive

    • By dell96
      I'm trying to make my first project but I'm stuck i don't know how to make my crate to start to spawn again when i hit the start button after i die.
      hoping someone can help!!!
      Crate.cs
      CrateSpawn.cs
      Cratework.cs
      GameController.cs
      GameManager.cs
  • Popular Now