Help with a custom control setup

Hi everyone

Very brief history.
Currently in the beginning part of a software development degree and decided to have a crack at a game in my spare time as a bit of a learning aid, so I am fairly new to both java and jMonkeyEngine.

I decided upon a third-person, space ship, pew pew game.

What I currently have in game:
Skybox & skymap
Lighting (sun & ambient light)
Blender ship model (as a geometry) and a camNode, attached to a playerNode.

I would like to implement a World of Warplanes style control system where by the ship always stays centre screen (more accurately slightly below, to allow for a cross hair) and the mouse controls the camera. The ship then realigns with the centre of the screen at the speed it’s stats allow.

Example: Flying straight I would be looking at the rear of the ship. I turn my view 90 degrees sharp right and I would be initially looking at the left side of my ship, until it realigned with the centre cross-hairs, at which point I would be looking at it’s rear again.

Hope that’s clear enough. I’m aware there are probably some complicated physics and vector maths in this but I’m game for the challenge.

Any help or advice about a direction to take with this would be gratefully appreciated :slight_smile:

Kind regards

What is it you want help with? Controls or camera?

For controls, if you don’t want to involve “complicated physics” you could just let the keyboard controls (up,down,left,right) rotate the spatial and then move it whichever way it points.
Start with this:
Use spatial.rotate and multiply by tpf.
After that, you can get the forward vector by using spatial.getRotation().getRotationColumn(2)
Then, spatial.move(forwardVector.mult(speed).multLocal(tpf)) to move it.
I’m sure this is in a tutorial somewhere, don’t know which though.

If you want to use physics, you can start here:

For the camera, you could try a ChaseCamera. It has a lot of the functionality you want, already built in.

I have managed to implement controls with the keyboard and mouse, unfortunately they’re controlling the wrong thing. They either control ship and the camera stays fixed behind or the ship rotates but the camera stays in a fixed position. It’s more the camera setup I’m having issues with.

I’ve added a short gif below of the sort of thing I am after, which shows the player controlling the camera and then the model aligns itself automatically:

From that I’m wondering whether it’s actually a first-person camera I need to which I attach the ship.

[EDIT] I wondering if setControlDir(ControlDirection.CameraToSpatial) from cameraNode is what I am after but it says it’s used with first-person flycam. Not sure how that works.

Aha. I thought it was the other way around you wanted.

setControlDir(ControlDirection.CameraToSpatial) will work, but there won’t be any inertia.
You will need to make the spatial’s rotation trail towards the camera rotation but only by a certain amount each update. Quaternion.slerp can help you (interpolation) with that.