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);

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.

This post of yours is the better part of a year old, but it helped me today. I’ve been continuing some simplistic experiments, for part of which I put the camera some 6.3 million meters above origin (c.f., “earth-sized” …). I had had flyCam.setMoveSpeed(100), but when I toned that down to “10”, suddenly I could not move along the Y-axis (but could move along the other two).

At first, I thought it was another (slightly more recent) change I had made, but couldn’t see why. Experimenting showed that no, it wasn’t that other thing, and further experiments showed that changing the setMoveSpeed alone could flip this light switch on or off.

Searching about brought this post to the surface, and this post perfectly explained the reason for what I’m seeing. So, thanks!

… I think I’ll have to look into your SiO2 camera handler …

1 Like

Glad it could help.

32 bit floating point bites a lot of people. Noticeable precision starts to fall off at about 65,000 meters where you will start to see physic jitter, etc…

In the original Mythruna, we teleported out to 1,000,000 x 1,000,000 one time just to see if the world would generate properly (it did) and found that we could not move at all.

2 Likes