Several First-Person camera pitfalls (speed and angle) [jME3]

[SOLVED, see at the end]

wow… I am having a hard time trying to figure out how to use my flycamappstate…

EDIT: my application will not initialize properly (the terrain wont show up and other things) if I do this:

@Override
public void initialize() {
	super.stateManager.attach(new FpsFlyCamAppState());
	super.initialize();
}

or this

@Override
public void initialize() {
    super.initialize();
    super.stateManager.detach(super.stateManager.getState(FlyCamAppState.class));
    super.stateManager.attach(new FpsFlyCamAppState());
}

EDIT: ok, I think to do it is currently impossible, I am in a loop trying to create my flycamappstate and not being able to, see:

the only possible place to add it seems here:

public Main() {
	super( new StatsAppState(), new FpsFlyCamAppState(), new DebugKeysAppState() );
}

I get several nullpointer exceptions because the order in which things are executed:

@Override
public void initialize() {
  // I cant initialize fpsFlyCam here because Camera is not instantiated yet...
  super.initialize(); //this creates Camera but also calls my Main.simpleInitApp() that access SimpleApplication.flyCam and crashes with NPE
}

the point is, I should be able to initialize flycam stuff at simpleInitApp(), but I cant if I have my own flycamappstate :frowning:

EDIT: ok, I am not using override on initialize() anymore; flycamappstate is only auto initialized after simpleInitApp() and before simpleUpdate(), so I moved my flycam init code to simpleUpdate() (with a boolean to run it on in the first frame), but I think there remained some conflict or some problem about, the game will not initialize properly :(, I will see what more I can find…

EDIT: SOLVED! the problem here was that, if I put a breakpoint and it happens on the first frame, the applicaion will not initialize properly, the terrain wont load and so on, everything ok now thx!

You can use app.enqueue instead of your boolean.

This the pattern of my latests projects :


AppSettings settings = new AppSettings(true);
// setup settings
SimpleApplication app = new SimpleApplication(){
  @Override
  public void simpleInitApp() {
  }
};
app.setSettings(settings);
app.start();
//Setup Camera
app.enqueue(() -> {
  app.getStateManager().detach(app.getStateManager().getState(FlyCamAppState.class));
  app.getStateManager().attach(new FpsFlyCamAppState());
  return null;
});


in context :

oh it has a queue!? cool!

but sometime ago I created my own queue as a Runnable and control how and where it runs :), may be I can throw some stuff on this queue too

I see that is lambda xp right? I havent moved to eclipse yet :frowning: hehe

btw I solved it, the breakpoint on the first update frame was breaking the application (timing?) I think

The syntax for jdk7, is something like

 app.enqueue(new Callable<Void>(){
  public Void call() {
    ///...
    return null;
  }
});

enqueued Callable are dequeued and called just before simpleUpdate (each Frame).

1 Like