[SOLVED] Implementing Character Movement: onAction()/onAnalog() vs. update()

Hi everyone!

There is something that has me quite confused for the last days. Where do I implement the character behavior (specifically, my 3rd-person character movement) that follows key/mouse input?

Various tutorials on this site and in the book (Kusterer) suggest using booleans in the onAction() method and poll for those in update(), where the actual walking, jumping etc. happens. The problem I have with that is that all these tutorials only seem to cover onAction(), whereas there are almost no examples that cover onAnalog(). Now, when I look into TestChaseCam.java, the movement of the teapot is handled by an analog listener that implements the moving right there in onAnalog().

Are there any best practises for this? Are these different ways of handling input equally valid? At a first glance, I’d say that implementing the actions directly in onAction() & onAnalog() is preferable, because using booleans as “intermediary” between these methods and the update loop seems like an unnecessary step.

Can anyone clarify this (if possible)?
Thanks!

both ways are valid, onAction() an onAnalog() both occur inside the update loop with the other calls to update like AppState.update() and Control.update()

the reason you would just want to have your action listeners set “flag” variables that your controls and appstates can check for is mainly for logic flow and code readability.

Typically inside your action listener your code focuses in on understanding what the user is trying to input, and inside your AppState/Control you focus in on how the inputs affect the game world. Your AppState/Control then just has to ask the actionlistener what its understanding of the user input is.

as your game becomes increasingly more complex and your controls and systems become more complex then benefits of doing it this way will pay off. If youre just making a test case or experimenting then it doesnt really matter.

also to add, remember that onAction/onAnalog are only called when those events occur, but update() inside of an AppState/Control are called every frame no matter what.

1 Like