How to center a scaled model on screen?

I have a stupid simple game, and everything is working exactly how I want it to behave:

// This is Groovy but that shouldn't matter; I can intermix lines of
// Java code and it will all work
class MyGame {
  static void main(String[] args) {
    Simulator simulator = new Simulator()

    AppSettings settings = new AppSettings(true);
    settings.put("Width", 600)
    settings.put("Height", 900)
    settings.put("Title", "My awesome Game")
    settings.put("VSync", true)
    settings.put("Samples", 4)


class Simulator extends SimpleApplication implements AnimEventListener {
    AnimChannel animationChannel
    AnimControl animationController
    Node avatar

    void simpleInitApp() {
        DirectionalLight directionalLight = new DirectionalLight()

        avatar = assetManager.loadModel('models/Ninja.mesh.xml') as Node
        avatar.localScale = 0.025f

        avatar.rotate(0.0f, 3.14159f, 0.0f)

        animationController = avatar.getControl(AnimControl)
        animationChannel = animationController.createChannel()

        flyCam.dragToRotate = true


    void simpleUpdate(float tpf) {
        if(gameSimQueue.peek()) {
            NinjaState ninjaState = determineNinjaState()

            if(ninjaState == ninjaState.Punch) {
                animationChannel.setAnim('Attack3', 0.5f)
                animationChannel.speed = 0.8f

    void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

    void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
        // No-op

    private NinjaState determineNinjaState() {
        // Omitted for brevity; doesn't really matter how this works

Except, when this runs, the Ninja model (Ninja.mesh.xml from the test-data.jar) renders on screen like so:

Where’s his head?!? If you look at my code, I had to scale the Ninja down significantly, and am worried that this is somehow throwing off default calculations. So, given his scaling, how can I center him on screen? Changing the height and width of the window has not helped me yet.

Move the object? Move the camera?

You are going to struggle every single second of this if you don’t dig in and learn some basic 3D stuff, really.

1 Like

Thanks @pspeed, I understand what you are saying.

In reality though, my spare time is extremely limited and I am just trying to get a very simple demo/proof-of-concept working, and centering the ninja on screen is literally the last tweak I need to make. In a few weeks I will have some major downtime and will be able to do a proper deep dive into the docs, but it was my hope that I’d be able to just finish this PoC, and the answer to this question is the key to that.

Inside of simpleAppInit I added camera.setViewPort(0.0, 0.0, 0.0, 0.0); but that is not working. It appears to me that I need to raise the camera up, but there are so many methods on the camera object, I feel totally overwhelmed.

I’m sure this is just a simple 1- or 2-liner. Any chance you could help me out this one last time, or at least point me to the right javadoc? Once I get this working I will absolutely read up on 3D basics as well as do that deep dive on jME docs. Thanks for any-and-all-help here!

I wonder which of camera’s methods you would use to “set” the “location”?

I wonder if there is even a method to set the location. Perhaps it is called setLocation()?

I imagine someone who is in so much of a hurry that his eyes are darting all over the page and only reading one character at a time. The advice would be “slow down to go faster”.

edit: also, interesting tip… if you let the fly cam stay enabled you can actually ‘fly’ the camera around until you find a spot you like. By default there are debug keys like ‘c’ that will dump the current camera location.

Ok… let’s talk.
We also have very limited spare time. Yet we’ve spend a fair amount of this time making an engine, with javadoc, and a very thorough documentation with very simple tutorials so that people wouldn’t feel overwhelmed.
You’ve asked like 20 questions for the last few day, every single one of which are answered in the documentation or the tutorals, yet… we still spend some our limited spare time answering and in every answer pointing you toward the documentation.
Now, when you say “I have very little spare time to read the doc”, I read “I’d rather waste your time than mine”. You waste the time we spend writing the docs, and you waste the time we spend answering you, so basically… you waste our time twice.
So tbh, even if I try hard, the only answer that comes to my mind is “fuck off”.


@hotmeatballsoup I’m just curious. Do you even know Java?
When I started back in the day. I had some Java experience. Not much, but enough. I went through all the tutorials and then I pretty much understood how things work.

Usually try to fix your things yourself. When you think you tried every possible way you know of, then it might be time to post a question on the forums.

EDIT: ctrl + space is also a very good way to explore how JME works.

All of this is written with the best intentions :wink:

@pspeed - thanks for the hint I’ll check it out

@nehon - I literally challenge you to a fist fight


Cool down guys.

That was not meant for real right?
Back to topic.

avatar.setLocation(-2, -2, 0);

play with the values and yes the tutorials also will show you how to use setLocation I guess.

If avatar is the spatial then I think you meant setLocalTranslation() and not setLocation().

I elect myself to represent JME in all future fist fights. I will also fight anyone who challenges my representation.


If that needs a team of fist fighters I’m in :smile:

@pspeed: Yes you are right, the IDE’s auto-complete helps me in that respect and I mostly take the right one :wink: Just want to give a pointer where OP can move that avatar around.

Ooh, 3D, java AND fist fights! JME has it all!


@hotmeatballsoup do yourself a favor. Read the tutorials … ALL OF THEM! If you don’t understand a tutorial then you are not ready to write code on that topic. At that point, get some knowledge about that specific topic … then re-read the tutorial. Following this process will get you far VERY quickly. Now, you are trying to create a video game … basically one of the hardest things to do if you don’t have the basic math skills and basic understanding required. That said, when you say you don’t have time to read the tutorials I say to you … GO PLAY CANDY CRUSH because video game creation is CLEARLY not for you!