After discussion with normen in a previous thread we came to this conclusion :
If you want to really "control" your snowboard you will have to check the current forces with getLinearVelocity and getAngularVelocity and give correct counter forces on your snowboard each tick. So if your torque around the x-axis is too high, you apply a counter-force. In this case using addForce() will work since you do it every tick.
So this is how my game currently works:
Now - it seems I should be calling applyForce every game tick - whereas at the moment it only gets called once per keypress - what is the best way to do this? Should I have something in the main game loop which applys a force to each model, and that force to be applied gets modified depending on the current forces and the addition of new forces because a or d has been pressed?
Hey! Your problem is pretty commonly encountered when setting up the controls, because the keypress method doesn't work like you're expecting it to. I made a thread that explains how to have a boolean that you can set using keypresses, and then read to apply the action every tick:
Actually, saving the values like kidneytrader suggested but in a threadsafe manner and then applying them in simpleUpdatePhysics() would be the "proper" and multithreading-compatible way for the physics implementation right now. This way they only get applied on every physics tick (which is 60fps by default).
Right… so i do the apply force in the main game loops simpleUpdate() method ?
I think this will require some refactoring of how I am currently handling movement - because I had all of this stuff abstracted away from the main game loop and in the event handling. It seems odd to set a force variable somewhere else - and then check it inside the main game loop!