I'm looking for the best way to make a reload system a gun in my game, however, i'm not sure about the best way to go about this. I know there is a timer variable, but i'm unsure of how i should use it. Or possibly I should use nanotime(), I don't know. Any input on this conundrum?
I hope I really understand what you mean. Personally, I recently succeeded in implementing the selection of a weapon (the "put back" and the "pull out") and the reload in my first person shooter. As you talk about a gun, I assume we speak about the same thing.
At first, if you plan to use nanotime or currentTimeMillis, you will need a "hack" to force the use of an high precision timer under Windows:http://bugs.sun.com/view_bug.do?bug_id=6435126
Secondly, princec already explained how to use a timer in general and it is used in that way in Ardor3D as far as I know. At each iteration:
- update the timer itself
- update the whole logic
Thirdly, I assume Rebirth's suggestion uses as a parameter the period between 2 frames in seconds (or time per frame). It should be enough.
Finally, I use a more complicated system in order to prevent the player from doing absurd things. For example, you don't want to allow your player to reload and select another weapon at the same time or to reload and attack at the same time. That's why I use a state machine with a kind of "scheduler". I will probably publish an article about that in my blog soon, it is a bit difficult to explain it without a schema.