Mousecontrol with gamecontrol?

Hi all,

Currently I am implementing a space shooter which has a ship that moves when the mouse moves, and a chase camera behind the ship.

However, I am using a gamecontroller with custom controllers attached to a ship node as such:

private void initInput(){
        manager = new GameControlManager();
        GameControl rollLeft = manager.addControl("Roll Left");
        rollLeft.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, false));

        GameControl rollRight = manager.addControl("Roll Right");
        rollRight.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, true));
        GameControl rollUp = manager.addControl("Roll Up");
        rollUp.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_Y, false));
        GameControl rollDown = manager.addControl("Roll Down");
        rollDown.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_Y, true));

        /* assign Controls to the rotation Controller */
        RotationController rollControl = new RotationController(player, rollRight,
                    rollLeft, 30f, Axis.Y);
        RotationController upDownControl = new RotationController(player, rollUp,
                    rollDown, 30f, Axis.X);
        GameControl accelerate = manager.addControl("Accelerate");
        accelerate.addBinding(new KeyboardBinding(KeyInput.KEY_W));       
        ActionController acc = new ActionController(accelerate,new AccelerateAction(this.player));
        GameControl brake = manager.addControl("Brake");      
        brake.addBinding(new KeyboardBinding(KeyInput.KEY_S));       
        ActionController br = new ActionController(brake,new BrakeAction(this.player));

        GameControl fire = manager.addControl("Fire");
        fire.addBinding(new MouseButtonBinding(MouseButtonBinding.LEFT_BUTTON));
        ActionController f = new ActionController(fire, new FireAction(this.player.getWeapon()));
        am = new AbsoluteMouse("my mouse", display.getWidth(), display.getHeight());
        am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display.getHeight() / 2, 0));

At the end of this code I also want to initalize an absolutemouse, so I have control over the mouse pointer. I want the mouse pointer to have a crosshair as the cursor and whenever I move this mouse this cursor moves around the screen and the ship follows this cursor. Just like with games like wing commander and such. However, in this implementation the cursor simply sits at the center of the screen and whenever I move the mouse the ship seems to follow the mouse but the cursor still sits in the center.

I think I am doing something wrong, should I assign all controllers to the absolutemouse and let the model follow this via the update sequence of the code?


Bump the same thing is happening for me.  I am not sure how to connect the absolute mouse with the game controllers.


Only a fast shot: Don't use these GameControllers, write your own which calculates a force based upon the mouseposition relative to the screens center and apply this force it to your ship every gamecycle.



GameControls are extremely powerful, but were not designed for mouse cursor positioning.  You could technically extend the functionality to provide a wrapper around the different mouse axis and then have it update the mouse position for you.  However, that may be more complicated than is necessary if you were to go another route.

What you need is to be able to determine the current position of the mouse cursor and based on that position in relation to the center of the screen apply direction to the ship.

I now have relative mouse control, but cant get absolute working?

Is there a simple way, perhaps by emulating a JoystickInput and setting up the binding to use JoyStickInputAxis?


I also want to create a space-shooter-like game with controls like mentioned before.

Is it really necessary to write own GameControl-Classes to get this working or does

the jME-API provide all necessary Classes? I'm really stuck on this, its just frustrating to

me because whatever I tried, it just don't work… It's a great API but I think theses

issues in the mouse-control-area could be done better…

Another user developed and contributed the functionality to do this…I believe it's in jME now.

Do you mean MouseOffsetBinding? Well, that does not really solve my actual problem.

At the moment, my camera is following my "ship" when I rotate with the mouse arount it.

But when i move the ship with WASD, the camera-location stays the same and the ship

is moving away. I can still rotate, but somehow I do believe I completely missunderstand

what CameraControl and FixedCameraPerspective really do.

Any advice?

i never used FixedCameraPerspective, but i think you want to use a CameraNode which you either attach to your ship (then the cam is basically mounted on the ship), or move it independantly through an InputController (like the ChaseCamera class in jme).

It really depends on how you want your camera behave or how much control you need to have over it.

CameraNode has done it. I never heard about that class, it made it a lot easier.

Thank you very much for this hint :slight_smile: