I am currently implementing a space shooter for my project. Already I have some nice rotating planets and such and a small box as a test node for my player which I can move using the ThirdPersonHandler class.
However, I have searched on this forum on how to implement mouse movement instead of keyboard movement, meaning the box should point to where iam moving with my mouse just like with a regular space game and acceleration and breaking will happen with the keys W and S. Next to this I use a chase camera to sit behind the ship and move accordingly with the mouse.
How do I do this? There are few resources on this matter so hopefully someone has the golden tip.
In my Spacegame i have a similar movement, but its very much arcade like, not realistic. and it dosen't feel very good
I used GameControl and RotationController for this.
If you want a realistic movement you should use Physics, but its a bit hard to implement, so this is a good start i think.
/* assign Keys and Mouse movement to the Controls */
GameControl rollLeft = manager.addControl("Roll Left");
rollLeft.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, true));
GameControl rollRight = manager.addControl("Roll Right");
rollRight.addBinding(new MouseAxisBinding(MouseAxisBinding.AXIS_X, false));
/* assign Controls to the rotation Controller */
RotationController rollControl = new RotationController(getPhysicsNode(), rollRight,
rollLeft, 0.5f, Axis.Z);
With this code, the physicsNode can be rolled around the Z axis either with the Keys A, D or with the Mouse.
You can create another Rotation controller to control Pitch, just use MouseAxisBinding.AXIS_Y instead of X.
That worked, I only had to inverse the X axis so it stayed with the camera and increase the movement speed a bit.
Hi, when I tried this i get no errors, but the character node (nor the camera) actually move?
Could the mouse be being deactivated somewhere else (the game is based on simplepassgame)
Could it be something to do with the fact I am using a chasecamera camera?
hmm maybe you are missing a rootNode.updateGeometricstate() call in the update method, but simpleGame should already handle this for you.
Its based on a simplepassgame, and I have now included rootNode.updateGeometricstate(0.0f, true); to the simpleupdate method
Still doesn't seem to be making any difference, any thoughts?
Could it be that using a chasecamera is implementing firstpersonhandler controls, which is why the mouse wont work?
I see there are various methods to do with the mouse in the chasecamera class, could this be the problem?