Hi, I have a bit of experience with Java but very limited experience with jMonkeyEngine. I’ve gone through the beginner tutorials, and reluctantly moved from an OO design to a Controller design. But I can’t run animations on my spatial for the life of me. I’ve got a playerControl class now to control the movement and whatnot of my player, and I want that to also handle the animation. So, I have this in the playerControl class constructor, which is already applied to the player spatial:
public PlayerControl(CharacterControl c, Camera cam) {
this.c = c;
this.cam = cam;
direction = new Vector3f().normalizeLocal();
plrDir = new Quaternion().normalizeLocal();
control = spatial.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Idle”);
}
Boom, NullPointerException. It simply refuses to work, even if I load it from the rootNode instead, in the main class. Here’s the hierarchy of my model, with the AnimControl shown:
I know this has been hashed over before, but none of them have helped me. I would just export the model as an Ogre, but I have issues with that, too. I really just need to figure out how to play the animations. It’s either that or just go back to coding 2d games in Eclipse…
If you’re in a custom control and the spatial field is null, that suggests that the control has not been added to any spatial yet. See the Javadoc for Spatial.addControl().
I’m not sure, to be completely honest. Like I said, I’m very new to this engine. I can tell you, though, my rhino model is imported from a .blend file via the import button on the SDK. The file then, of course, is a j3o. Then I set a Spatial equal to:
player = assetManager.loadModel(“Models/ent/player.j3o”);
That spatial is what I apply the control to. So, I think, yeah, it’s the blend file. Would it help if I put the whole code here so you could see? I know I’m jacking something up, I just came here because I have no idea what it is.
The control is on the sub-node, just look at the image yourself… This code is available in the forum about a hundred times but I post it again just for you:
[java]Node model = (Node)assetManager.loadModel(myModel);
Spatial subNodeWithTheControl = model.getChild(“rhino”);
AnimControl control = subNodeWithTheControl.getControl(AnimControl.class);[/java]
Thanks! I ran it through like you said, and it worked great. Thanks for bearing with me through all of my noob mistakes. You’ve all been such a great help!
One last question: Is there any way I could run through my animInit method in the controller only once without making a new variable? Because it yelled at me that I added the actionListener already, and since the spatial isn’t null all throughout the runtime that method is being called again. I know I could use a Boolean and fix it, but perhaps there is a better way?