Torque doesn't keep being applied

I am making a game where you can move a character (type third person shooter / rpg) and I want to use physics since all other method's don't seem to work. Now, I've based the character movements on lesson 8 of the physics tut. It can move a character, but not rotate it. I apply a torque for rotating it. Now I want when you press the left or right key, it keeps rotating right or left. What you need to do now is pressing the button repeatedly in order to keep rotating the characters. I want that it rotates as long as you press the button, and stops when you release the button. Does anyone know how to do this?

I guess you have installed a frictioncallback, which slows down the rotation (or the friction between the character and floor)?

If so, then you need to apply the torque repeatedly in intervalls (every 100 ms for example) as long as the button is pressed.

If you use a InputHandler.addAction() like the jumping in tutorial 8, then set allowRepeat to true.



Or to speak in Froggy Tongue, use GameControls and ActionRepeatController.


GameControl rotate = manager.addControl("rotate");
rotate.addBinding(new KeyboardBinding(KeyInput.KEY_LEFT));
ActionRepeatController rotateController =  new ActionRepeatController(rotate, 100,
                                  new Runnable() {
                                      public void run() {
                                          // yourPlayer.addTorque();
                                      }
                                  });


As long as KEY_LEFT is pressed, every 100 ms, the Runnable gets executed.
Core-Dump said:

I guess you have installed a frictioncallback,

I don't think so -- I copied the physics stuff from simple physics game and lesson 8.
Core-Dump said:
which slows down the rotation (or the friction between the character and floor)?

Could be, floor is very bumpy
Core-Dump said:

If so, then you need to apply the torque repeatedly in intervalls (every 100 ms for example) as long as the button is pressed.

How do i do this?
Core-Dump said:

If you use a InputHandler.addAction() like the jumping in tutorial 8, then set allowRepeat to true.

Again, how do I do this?
Core-Dump said:

To stop the rotating as soon as you release the button, i think you have to call clearForce() on Button release.

Okay, good to know -- but how do I check if the button is released (in update?)

hehe, i just modified my first response, while you wrote your answer, anyway.



if you use the InputAction like in Lesson 8 and set allowrepead true, then your Action will be executed with every update() cycle, which can be 100's of times per second depending on your framerate.

To avoid this, you need to make sure that the Action only gets executed every few 100 ms or so.

if (evt.getTime() > lastCall + 100) or something.



AllowRepeats is the last Variable in the addAction Method.

input.addAction( new MoveAction( new Vector3f( 2, 0, 0 ) ),
                InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_PGDN, InputHandler.AXIS_NONE, true);



But its probably easier to use ActionRepeatController (which i added in the first Response).

I'll try out both and see which one fits best. First I'll try the doing it the froggy way, of couse ;). Thank you very much, this means I  can finally do some programming.