Camera movement

So far I just have the BasicGame with a scenery. The scenery gets generated, and to be able to see what I have in the scene I use

cam.setLocation(...)

to place the camera near my objects.

Now I notice that moving around is not that easy. Yes, the mouse is bound and I can rotate and look at my scene. Movement seems to be missing though. While I can fly up pressing Q, there seems no way of coming down, and the other keys like wasd seem to not react. Or is the step increment so small that I simply do not notice?

How can I get in control of moving the camera myself?

Are you just using the default fly cam that comes with SimpleApplication by default?

1 Like

Guess so as I have not yet messed with it

By default, SimpleApplication includes https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
…which is controlled by:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/app/FlyCamAppState.java

You are free to disable it and replace it with whatever you want… ultimately it’s a good idea anyway.

My SiO2 library contains some slightly more advanced camera input handling that lets you plug in your own handlers, too… but by default moves the camera directly.

It has a chain of other dependencies that also probably end up being useful (mathd, lemur, etc.) It also does it’s calculations in double which may be better for large coordinates.

…though ultimately if you are leaving everything in its native unlocalized coordinates then you are going to have other problems. 32 bit float is really not very accurate for earth-sized datasets.

Thank you. Following your hint I figured that going down is ‘Z’, which is in a different location on my keyboard - but it works. So very likely I just want to modify the step size for now, and I will consider using your advanced camera.

Looking at The jME3 Camera :: jMonkeyEngine Docs I just want to use

cam.setMoveSpeed(100);

but that seems not possible on ‘my’ camera which is an instance of com.jme3.renderer.Camera.
In the JavaDoc I found FlyCamAppState (jMonkeyEngine3)
so it seems I want to get familar with AppStates now.

If you are in SimpleApplication then you can cheat by accessing the “flyCam” field:
https://javadoc.jmonkeyengine.org/v3.5.0-stable/com/jme3/app/SimpleApplication.html#flyCam

But if you want the “portable” way then getting the app state is the better way.
Either:
stateManager.getState(FlyCamAppState.class).getCamera()
Or from any BaseAppState subclass:
getState(FlyCamAppState.class).getCamera()

2 Likes

This has worked for me:

stateManager.getState(FlyCamAppState.class).getCamera().setMoveSpeed(300);