cam.getCamera() Error?

public enum InputMapping{
    RotateLeft, RotateRight, LookUp, LookDown, StrafeLeft, StrafeRight,
    MoveForward, MoveBackward, Fire, LeanLeft, LeanRight, LeanFree
}
private void addInputMappings(){
    inputManager.addMapping(InputMapping.LeanLeft.name(),
            new KeyTrigger(KeyInput.KEY_Q));
    inputManager.addMapping(InputMapping.LeanRight.name(),
            new KeyTrigger(KeyInput.KEY_E));
    inputManager.addMapping(InputMapping.LeanFree.name(),
            new KeyTrigger(KeyInput.KEY_V));
    inputManager.addMapping(InputMapping.Fire.name(), 
            new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping(InputMapping.RotateLeft.name(),
            new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(InputMapping.RotateRight.name(),
            new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(InputMapping.LookUp.name(),
            new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping(InputMapping.LookDown.name(),
            new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping(InputMapping.StrafeLeft.name(),
            new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping(InputMapping.StrafeRight.name(),
            new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping(InputMapping.MoveForward.name(),
            new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping(InputMapping.MoveBackward.name(),
            new KeyTrigger(KeyInput.KEY_DOWN));
    
    for(InputMapping i : InputMapping.values()){
        inputManager.addListener(this, i.name());
    }
    
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.inputManager = app.getInputManager();
    addInputMappings();
    
    //TODO: initialize your AppState, e.g. attach spatials to rootNode
    //this is called on the OpenGL thread after the AppState has been attached
}
public void onAnalog(String name, float value, float tpf){
    
    if(character != null){
        character.onAnalog(name, value, tpf);
    }
}
public void onAction(String name, boolean isPressed, float tpf){
    
    if(character != null){
        character.onAction(name, isPressed, tpf);
    }
    if(name.equals("Fire")){
        if(isPressed && character.getCooldown() == 0f){
            fire();
        }else{
            character.onAction(name, isPressed, tpf);
        }
    }
}

public void fire(){
    Ray ray = new Ray(cam.getCamera().getLocation(), //error on cam.getCamera()
            cam.getCamera().getDirection());
    
    collResults = new CollisionResults();
    for(Geometry g : targets){
        g.collideWith(ray, collResults);
    }
    if(collResults.size()>0){
        System.out.println("hit"+collResults.getClosestCollision()
                .getContactPoint());
        character.onFire();
    }
}
@Override
public void update(float tpf) {
    //TODO: implement behavior during runtime
}

@Override
public void cleanup() {
    super.cleanup();
    for(InputMapping i : InputMapping.values()){
        if(inputManager.hasMapping(i.name())){
            inputManager.deleteMapping(i.name());
        }
    }
    inputManager.removeListener(this);
    //TODO: clean up what you initialized in the initialize method,
    //e.g. remove all spatials from rootNode
    //this is called on the OpenGL thread after the AppState has been detached
}

}

//WHY DO I HAVE THAT FREAKING GET CAMERA ERROR! lol it’s been buggin’ the crap out of me

its in the public void fire() method

I can’t really help you for some reasons but I have a similar problem to yours. Maybe you could help me solving my problem and on the way you learn how to solve yours. This one is very similar to yours and driving me absolutely mad…

public void foo () {
   bar.getBar ().getFoo ();
}

Do you know why I’m always getting a BAR Error???

Could you help me debug this issue? Maybe we can find together a solution or a way to solve both problems.

Cheers
A monkey in need

1 Like

Well, I’ve been looking through my code and I believe its a instantiation problem.
The code is fine…it’s just knowing where to instantiate the objects…Vector3f objects.

That’s all I can say. It has nothing to do with the main class that contains all the methods for your model classes such as: bullet class, character class, or inputmanagement class(key pressing for actions and such).

I bought this cookbook online from the google store and its got good stuff on making your first FPS…but I got stuck on the Firing Non-Instant Bullets…So I just stuck with simple FPShooting. I also have been looking through the tutorials and seeing examples where the character shoots spheres at walls and such. But I still haven’t made my first person shooter yet. I’ve just decided to go back into blender and make some models and test them out in the hello tutorials. I’m new to jmonkey but I’ve had a decent amount of java practice and knowledge. Busy busy busy. The jme3test tutorials have everything though.

And yes sometimes it is a debug issue. because I have cleaned a project and all these silly errors go byebye. BUT…sometimes you have to install netbean plugins into your NetBeans Engine. So when you have the time check up on your NetBeans and make sure there aren’t any access plugins needing to be downloaded…Because I’ve recently learned that the JME runs off of NetBeans compilers in ways you won’t imagine. Just be sure to check for updates. And if u do have updates on NetBeans be sure to reinstall jmonkey after updating your NetBeans…because if you have firewall it may get a little messy…me so sorry.

I assume your code is in a AppState, and cam I the instance of com.jme3.render.Camera.

You should instance it in initialize method of your AppState.

To access class fields of the SimpleApplication the way you are used to, initialize them to local variables, as shown in the following AppState template:

public class MyAppState extends AbstractAppState {

    private SimpleApplication app;
    private Camera cam
    private Node rootNode;
    private AssetManager assetManager;
    private AppStateManager stateManager;
    private InputManager inputManager;
    private ViewPort viewPort;
    private BulletAppState physics;

    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        this.app = (SimpleApplication) app; // can cast Application to something more specific
        this.cam = this.app.getCamera();
        this.rootNode     = this.app.getRootNode();
        this.assetManager = this.app.getAssetManager();
        this.stateManager = this.app.getStateManager();
        this.inputManager = this.app.getInputManager();
        this.viewPort     = this.app.getViewPort();
        this.physics      = this.stateManager.getState(BulletAppState.class);
    }

    // ..
}

Then you can use cam.

Ray ray = new Ray(cam.getLocation(), cam.getDirection());

You don’t need cam.getCamera(), it’s non scene. Even app.getCamera() is OK.

1 Like

Step 1 when having an error and requesting help: Post the stack trace.

1 Like

Thanks guys I got it all repaired. I can’t believe I let simple stuff like instancing destroy me. I’ve had plenty of java practice…it’s just when I look at jmonkey and all its new methods and stuff I go “whoa”. Its just a lot to take in. I looked on GitHub and saw a lot of applications created. Can’t wait to push another envelope.