[Solved] Movement issues


I’m currently working on movement, and I’m a bit lost. I’m using JME for a top-down space game. The entire game takes place in the X-Y plane.

as a result I move my models in the Y or -Y direction. This should give me forward and backwards, based on the model rotation. Now, I set the rotation to new Quaternion(), which should be the basic rotation.

After adding some movement, it seems the model moves not only in the Y direction. Let me put in some code to demonstrate:


System.out.println(iwc.getRotation().getX() * FastMath.RAD_TO_DEG);

System.out.println("Moving with speed " + mc.getSpeed()

  • " on axis " + mc.getAxis() + " along rotation "
  • iwc.getRotation());

    System.out.println("moving from " + iwc.getLocation());



    multLocal(mc.getSpeed() * tpf));

    System.out.println("moving to " + iwc.getLocation());


    In here, mc.getAxis() = 1 and mc.getSpeed() = 100. The results of the log statements is:


    Moving with speed 100.0 on axis 1 along rotation (0.0, 0.0, 0.0, 1.0)

    moving from (0.0, 0.0, -450.0)

    moving to (0.0, 0.0014670892, -0.6601901)


    As you can see, I start with NO rotation, then how is it possible, if I specify I want movement on axis 1 (the Y axis), that both the value for the Y location and the value for the Z location change?

    I already have a simpler example, which works, so the error should be somewhere in my code. I just cant find it. All the inputs on this piece of code seem to be corrent, it’s just the output of this piece of code that’s wrong.

    I hope someone can help me out here, I’m stuck.


Just a word to future explorers:

If you find yourself calling getRotationColumn() and are not doing some kind of weird advanced matrix decomposition then you are doing things the hard way. As a rule, do not ever call this method unless you fully understand the cases where it is ok to do so. :wink:

1 Like

Yeh, not sure what your problem is, but a simpler solution would be to use direction vectors. For example, you have a model (a man) which is facing away from the camera. This direction vector would then be (0, 0, -1), or -Vector3f.UNIT_Z. If you rotate him around, you can always find the direction he is looking by multiplying his rotation by that initial vector:

[java]Vector3f forwardDirection = spatial.getLocalRotation().mult(-Vector3f.UNIT_Z);[/java]

you can then move him in that direction (don’t forget to normalize it!) each frame:

[java]spatial.move(forwardDirection.normalizeLocal().mult(tpf)); [/java]

hope that helps.

1 Like

Thanks wesrule, thats actually fixed it for some reason.