Problem with moving Player

Hi everyone,



I am currently re-integrating my balance board to my game and I got a little problem with that! I managed to get  horizontal and vertical values out of it!



So the structure of the balance board looks like this:



 


  1
             
|             |             |
|             |             |
-1
0
1
|             |             |
|             |             |
 
-1

These are the values I get, when I stand on my balance board!  So when my feet are at the top my horizontal value (up) is 1! When my feet are way at the bottom the horzontal value is -1;

The same with the vertical value! Way right = 1; Way left = -1

Now I want to move my player according to the values! I tried this in the update method:


x_axis +=  60f *  time * -(value(PlayerAction.X_AXIS));
z_axis +=  60f * time *  -(value(PlayerAction.Y_AXIS));
Player.getLocalTranslation().set(x_axis, 2, z_axis);



The problem is, that it only works if the value is greater than 0!

Does anybody have a clue what I should do better?

Thanks RapidM

What is value() ? Is it the method that can return values in the range -1…1?

Yes.



Values gives me the value of the balance board!



value(PlayerAction.X_AXIS) is X_AXIS

and

value(PlayerAction.Y_AXIS) is Y_AXIS





public void massInputReceived(BBMassEvent evt)
   {
      totalmass = evt.getTotalMass();
      
      //Print out the level of battery
       double massRightTop = evt.getMass(MassConstants.TOP, MassConstants.RIGHT);
       double massLeftTop = evt.getMass(MassConstants.TOP, MassConstants.LEFT);
       double massRightBottom = evt.getMass(MassConstants.BOTTOM, MassConstants.RIGHT);
       double massLeftBottom = evt.getMass(MassConstants.BOTTOM, MassConstants.LEFT);
      
      
       if (totalmass > 20)
         {  
            // deltas are +/- how much kg in each direction
            double horizontalDelta = (massRightTop + massRightBottom) - (massLeftTop + massLeftBottom);
            double verticalDelta = (massLeftBottom + massRightBottom) - (massLeftTop + massRightTop);
       
            // we now need to make them relative to mass and work out position
            X_AXIS = (horizontalDelta / totalmass  * DisplaySystem.getDisplaySystem().getWidth()) / DisplaySystem.getDisplaySystem().getWidth() ;
            Y_AXIS = (verticalDelta / totalmass * DisplaySystem.getDisplaySystem().getHeight()) / DisplaySystem.getDisplaySystem().getHeight() ;
       
         } else {
            X_AXIS = 0;
            Y_AXIS = 0;
         }
   }



Ok I got the forward and backward part working:



Player.setVelocity(60f * value(PlayerAction.X_AXIS));



value(PlayerAction.X_AXIS) gives me a value between -1 and 1!

Now I tried use the PlayerRotationAction from the tutorial for my rotation!


    public void rotateAction(float action, float time) {
        if(Player.getVelocity() > -FastMath.FLT_EPSILON && Player.getVelocity() < FastMath.FLT_EPSILON) {
            return;
        }
        //affect the direction
        if(value(PlayerAction.Y_AXIS) < 0) {
            modifier = 1;
        } else if(value(PlayerAction.Y_AXIS) > 0) {
            modifier = -1;
        }
        //we want to turn differently depending on which direction we are traveling in.
        if(Player.getVelocity() < 0) {
            incr.fromAngleNormalAxis(-modifier * 0.01f, upAxis); //-modifier * Player.getTurnSpeed() * 0.1
        } else {
            incr.fromAngleNormalAxis(modifier * 0.01f , upAxis);
        }
        Player.getLocalRotation().fromRotationMatrix(
                incr.mult(Player.getLocalRotation().toRotationMatrix(tempMa),
                        tempMb));
        Player.getLocalRotation().normalize();
     
    }



Problem: It only rotates right!

The values of vlaue(PlayerAction.Y_AXIS) fives me the values between -1 standing way left and 1 standing way right!

Now I want to rotate my Player according to these values! If the value is 0.8f it should turn right faster than 0.3f!
Same thing with the left side!

Help help help ;)

Managed to get it to work :wink: