Quick Question about FirstPersonHandler

Hi! I have a question regarding the FirstPersonHandler. Let's say I create an InputHandler fph = new FirstPersonHandler(cam,moveSpeed,turnSpeed). Now I want to change the moveSpeed dynamically via a slider.

However it seems not possible to get or set the speed values. The method fph.setActionSpeed(someSpeed) does not seem to apply for this case. I only got it to work by creating a new instance of the InputHandler each time the Slider is adjusted… though I think that's ugly. I then tried to extend the FirstPersonHandler Class like that:

this is the lines where I get the slider adjustments:

EDITED: … ne Trial…

               fph.move = slidervalue;

this is my extended class:

class MyFirstPersonHandler extends FirstPersonHandler{
   class MyFirstPersonHandler extends FirstPersonHandler{
   float move;
   MyFirstPersonHandler(Camera cam, float moveSpeed, float turnSpeed)
      super(cam, moveSpeed, turnSpeed);
      super.moveSpeed = move; //error: "cannot be resolved or is not a field"

It doesn't work though. I think the error is in the extended class or the variables. Any suggestions?  :|

Well, it would only change the move speed when the object is first created. setMoveSpeed changes the move speed, but you can see that the constructor is the only thing that calls anything from the parent class that passes in that variable. So basically this:

MyFirstPersonHandler(Camera cam, float moveSpeed, float turnSpeed){
   super(cam, moveSpeed, turnSpeed);

Is only called when the object is created, so it never know you updated it. You can't call this:

public void setMoveSpeed(float mSpeed){
   this.moveSpeed = mSpeed;   

Until after the object is created. Do you see what I mean? I can't think of how to fix it, I can just point out the problem. A possibility could be to change the jME source to take a parameter for the movement speed in the update method, then in your extension, pass in that variable every frame. I don't know if you want to change the jME source though.

mhm… since there is no get/set methods in the source class :frowning:

Since I do not want to change the source code I guess I need a new approach… which is to get both devices (keyboardhandler, mousehandler) from the firstpersonhandler, then handle the keyboard only, try to determine the speed of it and change it… somehow like that maybe  :?

Ah it worked that way :slight_smile:

// after figuring out that a KeyboardLookHandler is on the second position
// and a MouseLookHandler on the first position of the FirstPersonHandler

KeyboardLookHandler dev = (KeyboardLookHandler) fph.getFromAttachedHandlers(1);
dev.setActionSpeed(slidervalue); // adjust the speed
input.removeFromAttachedHandlers(fph.getFromAttachedHandlers(1)); // remove the old KeyboardHandler
input.addToAttachedHandlers(dev); // attach the new KeyboardHandler to the fph