Max cam rotation

Hi to all, first time I registered ; I went here because I need help using your game engine due to time problem for creating my own. I’m developing for a very long time ! I learned java, I already made a 2d game engine, a 2d game, a bukkit plugin, a minecraft mod and a minecraft moded server.

So you know, in all fps games you have a max yaw and pitch. The problem is that I can’t find a way to set the max cam rotation with your game engine.
In second, I would like to ask you about something weird while changing physics properties to real ones. Indead, with realistic physics properties of the player, sometimes the player is no-clipping the map and fell out of the world. That would be a problem in the fact of my game will have loos able stuffs on player death. And my entity system is destroying all entity’s that fell under the high of -128. So player will loose his stuff forever. Is that normal ?

Thanks for your future answers,

The default FlyByCamera moves the camera directly and thus is unsuitable for most games. (It’s great for tests and demos, though.)

You are better off writing the 10 or 15 lines of code to register input listeners and move your game’s player object directly.

1 Like

Ok thank you but, but I don’t understand completely what you said.

Do you mean I need to create my own camera and player to handle the camera correctly ?

And you did’nt answered my other question about player who’s nocliping. Maybe it’s a bug ?

FlyByCam moves the camera directly. But games don’t have cameras, they have players and the camera just happens to follow the player, either as his eye (first person) or behind him (third person).

In a real game, trying to do everything by moving the camera will only cause trouble and constant work arounds for this or that. (“How do I do head bob?” “How do I attach a gun to the ‘camera’?” “What does my camera go through walls?”, etc.) All of these things have simpler answers if the mouse+keyboard is moving the player instead.

So, yes, you will need to write your own “camera handler” except it won’t be handling a camera. It will be moving your player. You can already link a camera to a player with built-in JME stuff.

I have no idea about your other question but you also haven’t provided enough information for anyone to help.

I just restarted my ide today, and i just tried to launch my application. Yesterday all was working, just camera and noclip bugs were present. But today, the whole map has no longer any colision boxes ! It’s very very strange.
Now you are no cliping everything of the map ! I realy don’t understand anything… I’ve done nothing new on the code. The code broke by computer shutdown then restart…


Wow, i just solved the issue by changing a little bit the player colision shape…

Now i can use my game like before. But it still rest the cam problem and the noclip bug…

@Yuri6037 said: But it still rest the cam problem and the noclip bug...

noclip is usually called “tunneling” in the physics engine. If you search for that you should find a lot of discussions on what can cause it and tips on how to avoid it. One tip is to make sure the ground collision shapes are not extremely large compared to the player. Another is to make sure that your code do not force the player into the ground (for example by abusing setLocation).

Thank you ! I think that i found the origin of the tuneling problem : it’s because i’m using a test map (called from your team. Visibly this map has a large number of colision boxes problems same as some textures issues.

I took this map because of your ultra-ultima complicated map creation tool… The Valve Hammer Editor is much more simple than your one. Indead, i just want place a block and there is no buttons to select an area to create a 3d rectangle. In Hammer Editor i have this button. That’s why i just took a map from your team.

If you know any tutorial about the map editing tool, i will largely take.

For the cam problem, can you give me some more helps ? Like what class do i need to extends or implement, how does the cam system work on this game engine ?


So, can you help me making my camera to be ok ? Here is my code (The game main class) :

package fr.jme3mmo.client;

import com.jme3.asset.plugins.ZipLocator;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings;

public class JME3MMO extends SimpleApplication
implements ActionListener {

private Spatial sceneModel;
private BulletAppState bulletAppState;
private RigidBodyControl landscape;
private CharacterControl player;
private Vector3f walkDirection = new Vector3f();
private boolean left = false, right = false, up = false, down = false, sneak = false, sprint = false;

private Vector3f camDir = new Vector3f();
private Vector3f camLeft = new Vector3f();

public static void main(String[] args) {
JME3MMO app = new JME3MMO();
AppSettings settings = new AppSettings(true);
settings.put(“Width”, 1600);
settings.put(“Height”, 900);
settings.put(“BitsPerPixel”, 24);
settings.put(“Fullscreen”, false);
settings.put(“Title”, “JME3MMORPG - FPS by Yuri6037 (Early Alpha 0.0.1)”);
settings.put(“DisableJoysticks”, true);
settings.put(“VSync”, false);

public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();

//flyby camera for rotation, while positioning is handled by physics
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

// load the scene from the zip file and adjust its size.
//assetManager.registerLocator("", ZipLocator.class);
sceneModel = assetManager.loadModel("Scenes/TestScene.j3o");

// We set up collision detection for the scene by creating a compound collision shape and a static RigidBodyControl with mass zero.
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);

// We set up collision detection for the player by creating a capsule collision shape and a CharacterControl. The CharacterControl offers extra settings for size, stepheight, jumping, falling, and gravity. We also put the player in its starting position.
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setPhysicsLocation(new Vector3f(0, 10, 0));    

// We attach the scene and the player to the rootnode and the physics space, to make them appear in the game world.


private void setUpLight() {
// We add light so we see the scene
AmbientLight al = new AmbientLight();

DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());


// The key mapping init. Later this init part will cal a BrickBrokenDataFile to load saved player (user) settings.
private void setUpKeys() {
inputManager.addMapping(“Left”, new KeyTrigger(KeyInput.KEY_Q));
inputManager.addMapping(“Right”, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(“Up”, new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping(“Down”, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(“Jump”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping(“Sneak”, new KeyTrigger(KeyInput.KEY_LCONTROL));
inputManager.addMapping(“Sprint”, new KeyTrigger(KeyInput.KEY_LSHIFT));
inputManager.addListener(this, “Left”);
inputManager.addListener(this, “Right”);
inputManager.addListener(this, “Up”);
inputManager.addListener(this, “Down”);
inputManager.addListener(this, “Jump”);
inputManager.addListener(this, “Sneak”);
inputManager.addListener(this, “Sprint”);

// Handling key pressed
public void onAction(String binding, boolean isPressed, float tpf) {
if (binding.equals(“Left”)) {
left = isPressed;
} else if (binding.equals(“Right”)) {
right= isPressed;
} else if (binding.equals(“Up”)) {
up = isPressed;
} else if (binding.equals(“Down”)) {
down = isPressed;
} else if (binding.equals(“Jump”)) {
if (isPressed) { player.jump(); }
} else if (binding.equals(“Sneak”)){
sneak = isPressed;
} else if (binding.equals(“Sprint”) && up){
sprint = isPressed;

public void simpleUpdate(float tpf) {
    walkDirection.set(0, 0, 0);
    if (left) {
    if (right) {
    if (up) {
    if (down) {
    if (sneak){
        Vector3f var = player.getPhysicsLocation();
        var.y /= 2f;
        Vector3f vec = walkDirection;
        vec.setX(vec.getX() / 3.5F);
        vec.setY(vec.getY() / 3.5F);
        vec.setZ(vec.getZ() / 3.5F);
    } else {            
    if (sprint){
        Vector3f vec = walkDirection;
        vec.setX(vec.getX() * 3.5F);
        vec.setY(vec.getY() * 3.5F);
        vec.setZ(vec.getZ() * 3.5F);

    float y = player.getPhysicsLocation().y;        
    if (y <= -128F){
        player.setPhysicsLocation(new Vector3f(0, 10, 0));


Thanks by advance,

The existing FlyByCam code is available. You could look at it for inspiration.

I would look it up for you but Github’s code browsing interface makes me want to punch things. Though I suppose I can still use the google code link for now:

A general note: if you want to be successful at writing games then you are going to have to learn to dig around a bit. The problems like this are the easy ones. The answers are readily available in several different directions. The problems you will hit later may not have easy answers… may not even have answers here… so you will need to have the skills of figuring stuff out.